I need to connect to a SQL Server database using Windows Authentication. I can connect using SQL Server Authentication by setting the Username and Password properties of the MSSQLServerDatabase object, but instead I want to use the logged on user credentials, e.g. “Windows 8\Username”.
I read somewhere that the solution was to pass this as the Username and leave the Password empty but that doesn’t work.
Is there a way to do this?
You might be able to use WMI: http://www.insidesql.org/blogs/tosc/2008/06/27/bginfo-wmi-and-sql-server
Search on this site for WMI you will find some examples howto use WMI with OLEObject
That seems to be more about obtaining the credentials. I already have them but I’m not sure how to (or if I can) pass them. Ideally I shouldn’t have to; I was hoping there was a way to tell the MSSQLServerDatabase object to use Windows Authentication but it seems to only support SQL Server Authentication.
I read somewhere that you can do Windows Authentication with ODBC in the connection string and I can see how to do that. But I don’t want to use ODBC if I can avoid it.
For MSSQLServerDatabase, if you would like the use the windows username / password running the application to authenticate… I believe you would simply not supply username / password during database connection.
And that’s the answer. Doh! Thanks Rich.