I have the below query in my console appliaction
SqlConnection myConnection = new SqlConnection("user id=abc;" +
"password=xyz;server=test;" +
"Trusted_Connection=yes;" +
"database=tested123; " +
"connection timeout=30");
myConnection.Open();
When I run the above application, it is working fine .But when publish this, it is throwing an error for the other users who are not having access to this DB .To avoid this I have created one service account "abc" and added it to the required DB.But it is still failing with the below error .
System.Data.SqlClient.SqlException (0x80131904): Cannot open database "tested123" requested by the login. The login failed.
Login failed for user >> user who is running this app.
How to run EXE with some custom account for all the users ?
I think you have to remove this row
Trusted_Connection=yes;
Using Windows credentials and is 100% equivalent to:
Integrated Security=SSPI;
Or
Integrated Security=true;
If you don't want to use integrated security / trusted connection you will need to specify user id and password
More about .NET Data Provider for SQL here
More about connection string here
As you can see in MSDN
Integrated Security -or- Trusted_Connection
When false, User ID and Password are specified in the connection. When true, the current Windows account credentials are used for authentication.
This is because you've got Trusted Connection
in your connection string.
That means you're effectively using Windows Auth, not the details in the string. Remove that and you should be ok.
By using Windows authentication you're asking the application to make the connection as the user who is running it.
You could go to the web http://www.connectionstrings.com/ and find out the connection string of your specific data base.
On the other hand, there is another similar question about this here: SqlException: System.Data.SqlClient.SqlException (0x80131904)
Replace
Trusted_Connection=yes;
to
Integrated Security=false;
in your connection string.
User contributions licensed under CC BY-SA 3.0