I am writing a Windows service that needs to connect to an SQL server to get some information. However, the server does not allow me to connect: login failed for user [domain/username]. The strange part is that everything works completely from within the SSMS. I can log in, query the database, and everything works fine. It is only through the Windows service that it throws this error.
For reference, here is the connection string I use:
Data Source = sqlserveraddresshere; Start Directory = databasenamehere; User ID = domain \ username; Password = Password`
I doubt this is related, but when I try to use Integrated Security, I get my computer name instead of my own username. I am 99% sure that this is due to the fact that our anti-virus and monitoring software pushes the administrator user on top of my Windows session to do my job. In any case, just entering the correct username and password should work independently, right?
I looked at some other issues related to the same error, but they were all unrelated. From what I can tell, anyone who can infiltrate through SSMS can also access their SQL server through code. This is the most similar question I could find, although it did not help:
Unable to connect to SQL Server: "Login failed for user". "
Also, before you ask, I ALREADY TESTED FOR TYPE. In fact, I even tried using other user accounts to make sure there wasn’t something scared with my permissions. If you need me to post any code, let me know. Thank you for your help!
UPDATE:
IntegratedSecurity = true. , - , :
"mydatabase", . . > "MYDOMAIN\myUserName".