I am creating a website, but in the database I use windows authentication.
I know that you use this for SQL authentication
<connectionStrings>
<add name="NorthwindContex"
connectionString="data source=localhost;
initial catalog=northwind;persist security info=True;
user id=sa;password=P@ssw0rd"
providerName="System.Data.SqlClient" />
</connectionStrings>
How do I modify this to work with windows authentication?
5条答案
按热度按时间hrirmatl1#
Replace the username and password with
Integrated Security=SSPI;
So the connection string should be
luaexgnf2#
For connecting to a sql server database via Windows authentication basically needs which server you want to connect , what is your database name , Integrated Security info and provider name.
Basically this works:
Setting Integrated Security field true means basically you want to reach database via Windows authentication, if you set this field false Windows authentication will not work.
It is also working different according which provider you are using.
Integrated Security=true throws an exception when used with the OleDb provider.
h9a6wy2h3#
For the correct solution after many hours:
<add name="umbracoDbDSN" connectionString="data source=YOUR_SERVER_NAME;database=nrc;Integrated Security=SSPI;persist security info=True;" providerName="System.Data.SqlClient" />
Hope this will help.
4dc9hkyq4#
This is shorter and works
Persist Security Info not needed
5lwkijsr5#
If anyone comes looking for asp.net core, we will have to add connection string in appsettings.json
Source: add windows authentication sql server connection string