'SQL server Login Failed for User' error specifically when running windows service

  • Thread starter Thread starter guzzyc
  • Start date Start date
G

guzzyc

Guest
I keep getting the error 'Login Failed for User '<user's name>'' even though I've tried every fix I've come across. I've used the following connection strings but still no luck :

<add name="PostOffice"
connectionString="Data Source=serverName;Initial Catalog=DbName; User Id=userName; Password=123;Integrated Security=False; Trusted_Connection=False"
providerName="System.Data.SqlClient"/>


<add name="PostOffice"
connectionString="Data Source=serverName;Initial Catalog=DbName;Integrated Security=True; MultipleActiveResultSets=true"
providerName="System.Data.SqlClient"/>


I've tried using these connection strings on a console application and they worked with no hitches, but they constantly fail on the windows service. I've checked to ensure both sql server and windows authentication are ticked, I've added both NT AUTHORITY\SYSTEM and NT AUTHORITY\LOCAL SERVICE as users on ssms, I've rearranged the connection string a bunch of times but still this error. I'm really at a loss here. My cs code -


public void OnTimer(object sender, ElapsedEventArgs args)
{
// TODO: Insert monitoring activities here.
try
{
SqlConnection sqlcon = new SqlConnection();
sqlcon.ConnectionString = ConfigurationManager.ConnectionStrings["PostOffice"].ConnectionString;
sqlcon.Open();
}
catch (Exception ex)
{

throw;
}

}

Continue reading...
 
Back
Top