Skip to content

Commit

Permalink
Issue a warning into log when both instance name and port present
Browse files Browse the repository at this point in the history
See #605
  • Loading branch information
denisenkom committed Nov 3, 2020
1 parent 1e08a3f commit 2f2a555
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions tds.go
Expand Up @@ -838,6 +838,12 @@ func connect(ctx context.Context, c *Connector, log optionalLogger, p connectPar
defer cancel()
}
// if instance is specified use instance resolution service
if p.instance != "" && p.port != 0 {
// both instance name and port specified
// when port is specified instance name is not used
// you should not provide instance name when you provide port
log.Println("WARN: You specified both instance name and port in the connection string, port will be used and instance name will be ignored");
}
if p.instance != "" && p.port == 0 {
p.instance = strings.ToUpper(p.instance)
d := c.getDialer(&p)
Expand Down
8 changes: 7 additions & 1 deletion tds_test.go
Expand Up @@ -227,12 +227,18 @@ func (l testLogger) Println(v ...interface{}) {
func TestConnect(t *testing.T) {
checkConnStr(t)
SetLogger(testLogger{t})
conn, err := sql.Open("mssql", makeConnStr(t).String())
conn, err := sql.Open("mssql", os.Getenv("SQLSERVER_DSN"))
if err != nil {
t.Error("Open connection failed:", err.Error())
return
}
defer conn.Close()
row := conn.QueryRow("select 1")
var val int
err = row.Scan(&val)
if err != nil {
t.Error("Scan failed:", err.Error())
}
}

func simpleQuery(conn *sql.DB, t *testing.T) (stmt *sql.Stmt) {
Expand Down

0 comments on commit 2f2a555

Please sign in to comment.