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

Windows Authentication with user id in the "DOMAIN\User" format does not function

Open AbsorbJonny opened this issue 6 years ago • 3 comments

I'm working with the following project which makes use of this library and I'm unable to get Windows Authentication functioning: https://github.com/free/sql_exporter

It appears that the reason sql_exporter isn't working for me is due to an issue in go-mssqldb. Right at the top of the README.md for this project it says "Windows Authentication user id in the DOMAIN\User format". But then this happened:

https://go-review.googlesource.com/c/go/+/87038

Consider the following DSN for Windows Authentication:

'sqlserver://MYCOMPANYDOMAIN\bob.jones@SQL-SERVER'

This produces the error "net/url: invalid userinfo" which is coming from that updated validation code that does not support the "" character, a character your README says to use.

Further, please provide a DSN example for Windows Authentication in your README, you have a lot of SQL Authentication examples and no Windows Authentication examples even though you claim to support it.

Thanks.

AbsorbJonny avatar Jan 18 '19 17:01 AbsorbJonny

Those are fair points. I wasn't even aware of the mentioned CL. We should probably see about adding a test for this and updating the README.

kardianos avatar Jan 22 '19 18:01 kardianos

For anyone bumping into this, it looks like replacing the \ with the %5C escape sequence works. So sqlserver://MYCOMPANYDOMAIN\bob.jones@SQL-SERVER needs to be rewritten as sqlserver://MYCOMPANYDOMAIN%5Cbob.jones@SQL-SERVER.

@kardianos Would you be interested in having some code in this project which escapes the backslash character in the connection string, so users won't have to do that themselves?

mihaitodor avatar Jun 29 '21 15:06 mihaitodor

Can we include @mihaitodor fix or it was already? Lucky with this thread that solved a long time problem for me, forced to use instead sql authentication.

mihaibudurescu avatar Jan 25 '23 16:01 mihaibudurescu