I have developed a Windows Service which stores and retrieves its MSSQL connection string in the registry. However I am experiencing that when my service attempts to connect with the string retrieved from the registry it blatantly ignores the UID and PWD specified.
I then compiled and ran the application as a console application and naturally that worked, since the console application was run with the rights of my own user account, whereas the service was run with the Local System account. The service connected successfully to the database when I specified that the service should be run as my own user account.
My conclusion is that when retrieved from the registry an application for some reason does one or both of the following:
- Ignores the UID and PWD specified.
- Automatically assume that the connection should be made in Trusted mode (Trusted_Connection=true)
It is worth mentioning that I have indeed specified Trusted_Connection=false in the connection string stored in the registry.
This is my connection string:
SERVER=.\SQLEXPRESS;DATABASE=mydb;UID=myid;PWD=mypwd
Is anyone able to shed some light on this matter? I would very much like to be able to utilize the user id and password stored in my connection string.
I take it you have SQL Server Authentication switched on?
With integrated authentication (recommended) you need to use change the service Run-As account to an account which has a SQL Server login.
I.e.