2

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 ?

pravprab
  • 2,301
  • 3
  • 26
  • 43
user3543884
  • 67
  • 1
  • 2
  • 9

4 Answers4

2

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.

Baximilian
  • 885
  • 7
  • 25
  • Thanks man it is working. But i have one question when we publish our web application in IIS ,we specify account details in application pool settings ,Do we have same mechanism for console application instaed of hard coding account details in the code – user3543884 Jul 11 '14 at 07:26
  • @user3543884 You can use app.config to store connection string in your console application. This can help you with flexibility – Baximilian Jul 11 '14 at 07:34
0

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.

dougajmcdonald
  • 19,231
  • 12
  • 56
  • 89
0

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)

Community
  • 1
  • 1
Pablo Caballero
  • 340
  • 2
  • 10
0

Replace

Trusted_Connection=yes;

to

Integrated Security=false;

in your connection string.

tom
  • 719
  • 1
  • 11
  • 30