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.
Questions:
Why is the system completely ignoring the connection string I am specifying?
Is there a work around to this?
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.
User contributions licensed under CC BY-SA 3.0