title: SQL Server Authentication behaves differently under different service accounts
body: <p>I have an application, which needs to run on Windows under a given service account. The .NET application connects to an MSSQL database and in the connection string I have specified the SQL server authentication used, namely</p>
  
  <pre><code>&lt;add name="conn" connectionString="Data Source=(localdb)\MSSQLLocalDB;initial catalog=MyDB;User Id=testuser;Password=xxx" providerName="System.Data.SqlClient" /&gt;
  </code></pre>
  
  <p>If I run SSMS under my regular domain account, then I can use the SQL user 'testuser' to connect to the database. However, if I run SSMS under the service account that should run the application, then I receive "Login failed".
  (And the same happens when running the service).</p>
  
  <p>I've spent more than a day looking into this problem, so if anyone has any ideas what might be wrong, I would very much appreciate it.</p>
  
  <p><strong>Update:</strong>
  The error message in the SQL server log is</p>
  
  <pre><code>07/12/2017 12:18:32,Logon,Unknown,Login failed for user 'testuser'. Reason: 
  Could not find a login matching the name provided. [CLIENT: &lt;named pipe&gt;]
  07/12/2017 12:18:32,Logon,Unknown,Error: 18456&lt;c/&gt; Severity: 14&lt;c/&gt; State: 5.
  </code></pre>
  
  <p>But if I log onto SSMS using my domain account, 'testuser' is listed under Security --> Logins.</p>
  
  <p>The SQL Exception that happens, when I try to start the service, is</p>
  
  <p>The service did not start successfully
  System.Data.SqlClient.SqlException (0x80131904): Login failed for user 'testuser'.
     at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling)
     at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)</p>
  
  <p>I've omitted some of the stacktrace, because it was quite long.</p>