amehanov
asked on
,Net Console App cannot connect to SQL server w/ correct credentials
I am writing a .Net console application. Using MS SQL 2005 and .Net 4. To connect to SQL I am using the SqlConnection class. The code works just fine on my local machine against my local db. However, when I change the connection string to point to a network SQL server, it throws an exception indicating that the login failed. I know the credentials work against the db as they are the same credentials that many of our web apps are using and they have no problem. I get the same result (against the remote SQL server) running the code either locally or on another server. Can anyone shed some light on this?
Can you post a sanitized copy of your connection string?
ASKER
szConn = @"Server=xxxxx;Initial Catalog=Users;uid=domain\u ser;pwd=pa ssword";
Hmmm... Was this paraphrased? I've understood passing a username and password in this manner (note User Id and Password):
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
It cannot be uid=domain\user;pwd=passwo rd, that implies you are mixing Windows Authentication with SQL Server Authentication.
It is either standard:
Server=xxxxx;Database=User s;User ID=myUsername;Password=pas sword;Trus ted_Connec tion=False ;
Or Trusted:
Server=xxxxx;Database=User s;Trusted_ Connection =True;
It is either standard:
Server=xxxxx;Database=User
Or Trusted:
Server=xxxxx;Database=User
Disregard http:#35268023 . In browsing the MSDN, I see you can use either; www.connectionstrings.com didn't show it when I looked at it.
ASKER
So, just to be sure, I changed my connection string to:
szConn = @"Server=server;Database=U sers;User ID=domain\user;Password=pw d;Trusted_ Connection =False;";
Exact same result.
szConn = @"Server=server;Database=U
Exact same result.
>>Exact same result. <<
As I stated you cannot do it that way. You need to decide whether you want to use Windows Authentication or SQL Server Authentication.
As I stated you cannot do it that way. You need to decide whether you want to use Windows Authentication or SQL Server Authentication.
So how about we ask this way:
Is the login you are trying to use was it setup using Windows Authentication or SQL Server Authentication?
Is the login you are trying to use was it setup using Windows Authentication or SQL Server Authentication?
ASKER
I read your post and II changed the connection string to the standard one (as per your specification in your post) when I last posted. And it does not work. I get the same result as the original connection string.
Unfortunately, if you are using this:
szConn = @"Server=server;Database=U sers;User ID=domain\user;Password=pwd;Trusted_ Connection =False;";
Than this is not a login using SQL Server Authentication.
szConn = @"Server=server;Database=U
Than this is not a login using SQL Server Authentication.
ASKER
That being the case, then if I understand you, I have to use the following connection string:
Server=xxxxx;Database=User s;Trusted_ Connection =True;
And if that is the case, the app will run under the credentials of who ever is logged in - and that means whoever wants to run this .exe must have their user account added to the db?
Server=xxxxx;Database=User
And if that is the case, the app will run under the credentials of who ever is logged in - and that means whoever wants to run this .exe must have their user account added to the db?
>>and that means whoever wants to run this .exe must have their user account added to the db? <<
That is correct. Regardless of how you connect to a database (SQL Server Authentication or Windows Authentication) that login is required to be added in the database in order for it to be accepted.
That is correct. Regardless of how you connect to a database (SQL Server Authentication or Windows Authentication) that login is required to be added in the database in order for it to be accepted.
ASKER
Is there any way to configure the connection string to allow the app to log in as a particular domain user (so that any individual can use the app and not need their account added to the db)?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.