Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSSQL connection uri with instance name #310

Closed
Santhin opened this issue May 25, 2024 · 2 comments
Closed

MSSQL connection uri with instance name #310

Santhin opened this issue May 25, 2024 · 2 comments

Comments

@Santhin
Copy link

Santhin commented May 25, 2024

Issue Description

  • Description of the issue:

While trying to test the env connection for the mssql db with the instance name I cannot connect due to adding the default port number.
Based on the docs from Microsoft:

For optimal connection performance, you should set the portNumber when you connect to a named instance. This will avoid a round trip to the server to determine the port number. If both a portNumber and instanceName are used, the portNumber will take precedence and the instanceName will be ignored.
  • Sling version (v1.2.10):

  • Operating System (mac):

While providing the url

sqlserver://myuser:mypass@host.ip/my_instance?database=master

The code is adding port number which is creating the connection issue

sqlserver://myuser:mypass@host.ip:1433/my_instance?database=master

I've tested uri with go-mssqldb and it worked properly

import (
    "database/sql"
    "log"
    "fmt"
    _ "[github.com/microsoft/go-mssqldb](http://github.com/microsoft/go-mssqldb)"
)
func main() {
    conn, err := sql.Open("sqlserver", "sqlserver://myuser:mypass@host.ip/my_instance?database=master")
    if err != nil {
        log.Fatal("Open connection failed:", err.Error())
    }
    defer conn.Close()
    err = conn.Ping()
    if err != nil {
        log.Fatal("Cannot connect: ", err.Error())
    }
    fmt.Println("Connected!")
}

For time being the workaround for that is to locally compile without this line
https://github.com/slingdata-io/sling-cli/blob/main/core/dbio/database/database_sqlserver.go#L40

@flarco
Copy link
Collaborator

flarco commented May 25, 2024

Thanks for raising this. Interesting, didn't know about the port number vs named instance logic for MSSQL.

@flarco
Copy link
Collaborator

flarco commented May 25, 2024

Done, see fe03d9c
Feel free to test and reporting any issues.
Closing.

@flarco flarco closed this as completed May 25, 2024
@flarco flarco mentioned this issue May 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants