Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connect to Mssql server in c# with Domain Account

Status
Not open for further replies.

ralphtrent

Programmer
Jun 2, 2003
958
US
Hello
I posted this in the c# forum, but someone suggest that I post here also. I need to connect to an MSSQL server in c# code using my domain account. Any ideas on how I would do that?

I have tried the following to now avial.

Code:
private string _strConnString = "server=[ServerName];database=[
DatabaseName];uid=[Domain]\\[UserName];password=[Password]";

[green]//returns login failed for user [Domain]\\[UserName][/green]

private string _strConnString = "server=[ServerName];database=[
DatabaseName];Trusted_Connection=true";

private string _strConnString = "server=[ServerName];database=[
DatabaseName];Trusted_Connection=yes";

[green]//both return login failed for user null[/green]

I am able to connect to the server using Query Analyzer and selecting Windows Authentication.

Any Ideas?
 
HAve a look here.


- Paul
10qkyfp.gif

- If at first you don't succeed, find out if the loser gets anything.
 
Yeah i've been there. It looks like there is no way to pass a custom Windows user on the command line in sql.net. The only way to do this is to "impersonate" in the web.config file.

Thanks
 
I replied to your thread in the C# forum. I don't believe this should have been directed to this forum although it's understandable why the other member did

[sub]____________ signature below ______________
You are a amateur developer until you realize all your code sucks.
Jeff Atwood[/sub]
 
The only way to connect to SQL Server via a specific account other than the one that the application is running under is to impersonate the other account via the .config file.

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top