Hi Guys,
I have a tool written in C# which connects to a remote SQl server 2005. Its working fine while I use "Integrated Security". However, I want to login the database using another credential instead of using the currently credentials associated with the tool. The reason for this was because not all the users using this tool have permission to access the database. So, I need sort of impersonation to allow any user using this tool to connect to the database.
Is there any simple and efficnet way to do this Thanks.

SQl server authentication issue in C#
yarrick
I don't know if you have SQL Server Management Studio, its a really good graphical tool. Use that tool and create a new database and name it say test...
Create a new User : say (test1) and some password : say (testingconnection) and make test1 owner of test database...
now try using this connection string and see what happens :
Data Source=localhost or address of the machine;Initial Catalog=test;User Id=test1;Password=testingconnection;
slledru
yeah, thats exactly what I tried at the beginning. But an error occured while the connection was being openned. I checked the server error log and it gave me:
Source Logon
Message
Login failed for user 'domain\user'. [CLIENT: x.x.x.x]
Error: 18456, Severity: 14, State: 6.
I also checked MSDN for state=6.
2
User ID is not valid.
5
User ID is not valid.
6
An attempt was made to use a Windows login name with SQL Server Authentication.
Sorin Sandu
cb3431
Hi
the username & password in the connectionstring needs to be the same as an sql server user (with sql server authentication)
if you want to use the domain account you should impersonate the aforementionned user when you access the database
Hope this helps, please close the thread if it does
JavaBoy
Hi
please close this thread by clicking the "was this post helpful" yes button on the answers that helped you out
Gurpreet Singh Gill
I have checked the configuration of SQL server 2005. Both integrated and SQl server aythentication are enabled by default/ So, I didn't change anything.
My question is : the user id/password pair in connection stirng is the same as the windows login username/password pair
DQM
You can use this line as a Connection String and should do it
Data Source=localhost or address of the machine;Initial Catalog=NameofDatabase;User Id=username;Password=password;
GustavoPollitzer
Remmie
Aaron Leiby
Thank you very much for you guys suggestions.
I have figured it out that the login failure was due to my confusing "windows authentication account" with "sql authentication account". I was not aware that I was providing windows account in the "connection string". Now, after I created a new "sql authentication account", the connection issue was resolved.
Thanks again!
Jocchan
that means, sql server authentication is not enabled. Do you mean I just need to enable both authentications Let me try. But is this a good practise
Thanks