denisenkom / go-mssqldb

Microsoft SQL server driver written in go language
BSD 3-Clause "New" or "Revised" License
1.81k stars 493 forks source link

Fix an issue where Host is named instance name #707

Closed srdan-bozovic-msft closed 2 years ago

srdan-bozovic-msft commented 2 years ago

For Microsoft SQL Host could take form [server]\[instance]. Without this fix LookupIP will fail in this scenario.

srdan-bozovic-msft commented 2 years ago

@kardianos could you help review? Thx!

kardianos commented 2 years ago

@srdan-bozovic-msft This seems wrong to me. msdsn.Config contains separate Host and Instance fields. If you manually populate that struct, does it work? If so, then any change must happen in the msdsn package.

What configuration DSN format do you use? If you are using the URL based DSN format, does it work? For instance, if you use: sqlserver://<user>:<pass>@<host>[:port]/<instance?database=<db-name> will it work?

Parsing a host from instance within the tds.go isn't correct.

shueybubbles commented 2 years ago

oh and there should be a test included.

srdan-bozovic-msft commented 2 years ago

Thx for the guidance @kardianos.

The problem I was trying to solve has been exposed in routing scenario, where both Host and Instance were assigned to host.

I made another commit to address this.

Is this proper way to fix the issue?

kardianos commented 2 years ago

@srdan-bozovic-msft So if I understand correctly, the DNS entry for the host is "blah\Foo"? I need a concrete example to work from first. Please fill in the following details of a hypothetical example:

  1. DNS A Record that resolves to the host:
  2. Instance Name:
  3. Value of msdsn.Config.Host
  4. Value of msdsn.Config.Instance

Once I have these four values, I might begin to understand.

srdan-bozovic-msft commented 2 years ago

@kardianos Driver receives from the server routing information code pointer "audit-test-server.database.windows.net\f7716e6f65ef"

Currently all of that is copied to a Host while it should be split btw Host and Instance

msdsn.Config.Host = "audit-test-server.database.windows.net" msdsn.Config.Instance = "f7716e6f65ef"

wifidoneright commented 2 years ago

When is the next release slated to come out? i am excited to see this patch in the version pulled from go get -u