Why is SQL Server using a different user to create the session?


I am trying to connect to SQL Server database from a .NET Core web application, here is the connection string I am using:

Server =.; Database = DBNAME; User Id = tb; Password = pass; Trusted_Connection = True; MultipleActiveResultSets = True;.

The previous setup generates an exception:

An error occurred using the connection to database 'DBNAME' on server '.'. System.Data.SqlClient.SqlException (0x80131904): Error opening session for the user 'MyDomain\ServerMachineName$'.

I think it is trying to connect using another domain account that I don't even see in the list of database users under security tab, nor in the users of the server instance.

In the startup file, the related configuration is:

services.AddDbContext<MyDBContext>(options => options.UseSqlServer(Configuration.GetConnectionString("MyConnectionString")));

I tried adding different users with the required privileges to the SQL Server instance and to the particular DB, but none of these worked.


  1. Why is the system completely ignoring the connection string I am specifying?

  2. Is there a work around to this?

asked on Stack Overflow Sep 26, 2019 by TiyebM • edited Sep 29, 2019 by TiyebM

1 Answer


What Trusted_Connection = True; means is ignore the passed in user id and password and instead use the windows credentials of the user running the program. As your program is likely running as a service the "user" it runs as is MyDomain\ServerMachineName$.

Setting trusted connection to false will have it use the userid and password provided in the connection string.

answered on Stack Overflow Sep 26, 2019 by Scott Chamberlain

User contributions licensed under CC BY-SA 3.0