go-mssqldb icon indicating copy to clipboard operation
go-mssqldb copied to clipboard

Unable to open tcp connection with host 'localhost:1443': dial tcp 127.0.0.1:1443

Open trustieee opened this issue 1 year ago • 1 comments

Describe the bug

Cannot connect to named MSSQL server running locally.

> unable to open tcp connection with host 'localhost:1443': dial tcp 127.0.0.1:1443: connect: connection refused

EDIT This seems to only occur when trying to connect to my SQL Server instance running on Windows, from a go app running in WSL.

To Reproduce

I've tried various connection string formats:

str1 := "server=localhost,mssqlserver2022;port=61821;user id=sa;password=sa;database=FooDB"
str2 := "server=localhost,mssqlserver2022;port=1433;user id=sa;password=sa;database=FooDB"
str3 := "server=localhost/mssqlserver2022;user id=sa;password=sa;database=FooDB"
str4 := "server=localhost;user id=sa;password=sa;database=FooDB"
str5 := "server=localhost:1433;user id=sa;password=sa;database=FooDB"
str6 := "server=localhost\\mssqlserver2022:1433;user id=sa;password=sa;database=FooDB"
str7 := `server=localhost\mssqlserver2022:1433;user id=sa;password=sa;database=FooDB`

// try with sqlserver
connection, err := sql.Open("sqlserver", str)
// try with mssql
connection, err := sql.Open("mssql", str)

I have a C# app on the side which uses this connection string, and it succeeds:

await using var connection = new SqlConnection(
"""
persist security info=false;
server=localhost\mssqlserver2022;
initial catalog=FooDB;
user id=sa;
password=sa;
""");

I've tried import _ "github.com/microsoft/go-mssqldb" and import _ "github.com/denisenkom/go-mssqldb"

Expected behavior

It should connect

Further technical details

SQL Server v. 16.0.1105.1 Windows 10 Home

trustieee avatar Jan 09 '24 15:01 trustieee