Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change user of windows authentication connection string in C#

When I want to connect to SQL Server 2008 via SSMS in windows authentication mode I get the following error:

login failed for user UserDomainName\UserName

I installed my SQL Server in mix mode and set user to NT Authority\system , how can I create a connection string with "UserDomainName\UserName" user not with "NT Authority\system" user in C#?

like image 469
Shima.Y Avatar asked Dec 20 '25 09:12

Shima.Y


1 Answers

Store the connection string in Web.Config or App.Config file

<connectionStrings>
<Add name="CS" ConnectionString="DataSource=.;Database=Sample;Integrated Security=SSPI" ProviderName="System.Data.SqlClient"/>
</connectionStrings>

then you can read the connection string property using System.Configuration namespace (dll)

string conStr = ConfigurationManager.ConnectionStrings["CS"].ConnectionString;

how can I create a connection string with "UserDomainName\UserName" user not with "NT Authority\system" user in C#?

Then use SQL Authentication mode and not windows authentication

ConnectionString="DataSource=.;Database=Sample;user id = test; password=test"
like image 125
Rahul Avatar answered Dec 21 '25 22:12

Rahul