I have an asp.net core web application. Here I am trying to get data from my SQL Server. for that I am configuring the appsettings.json
file with below text.
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"QuickKartDBConnectionString": "data source=MyServerName;initial catalog=ProductDB;Integrated security=False;User ID=User1;Password=User1@123;"
}
While debugging the code I found it is trying connecting to ProductDB
using Windows login. I am getting this error:
Cannot open database "ProductDB" requested by the login. The login failed.
Login failed for user 'mydomain\kcs.sahoo'
Please help me to sort out the issue.
Thanks in advance!
3条答案
按热度按时间wxclj1h51#
you can use this connection string for connect with Windows login
you can use this connection string for connect with user sql
status Server authentication in security is sql server and windows authentication mode
way change Server authentication to Mixed Authentication(sql server and windows authentication mode)
Log in to the Microsoft SQL Server Management Studio with a predefined user account, or if one was not set up for SQL authentication, use Windows Authentication.
Right-click the server you wish to modify and then click Properties.
Select the Security Page.
Under the Server authentication heading choose either the desired authentication: Windows Authentication or SQL Server and Windows Authentication mode.
Click OK.
At this point the SQL server must be restarted. To do so, right-click the server you have just modified and select Restart.
If SQL Server Agent is running, it must also be restarted.
lhcgjxsq2#
There are a few things that you're going to want to check:
appsettings.json
files: one for production and one for development. Check to make sure that you updated the value inappsettings.development.json
for your connection string.0qx6xfy63#
You need this part
Integrated Security=SSPI
in connection string for windows authentication.You could try configure your db with
SQL Server and windows authentication mode
Last but not least,not store your secrets in appsettings.json,check this document related with secret storage