简体   繁体   中英

SQL Connection String appsettings.json

This is my connection string

{
  "Data": {
    "PhotoGalleryConnection": {
      "ConnectionString": "Server=WINDOWS-B7MJR5T\\SQLEXPRESS;User Id=sa;password=allah;Database=PhotoGallery;Trusted_Connection=True;MultipleActiveResultSets=true"
    }
  }
}

And I am facing this exception

An exception of type 'System.Data.SqlClient.SqlException' occurred in Microsoft.EntityFrameworkCore.dll but was not handled in user code Additional information: Cannot open database "PhotoGallery" requested by the login. The login failed.

It should work after You delete Trusted_Connection=True; from connection string.

If you specify either Trusted_Connection=True; or Integrated Security=SSPI; or Integrated Security=true; in your connection string THEN (and only then) you have Windows Authentication happening. Any user id= setting in the connection string will be ignored. Found in here: When using Trusted_Connection=true and SQL Server authentication, will this effect performance?

请在窗口菜单中搜索服务

Please search services in the window menu, it will show you the local services then go to SQL server services and refresh all, then go to the SQL server management studio and by using SQL authentication please provide username and password, you will be able to use the SQL server. for appsetting.json update, trusted_connection is used for window authentication not for SQL server authentication by using username and password

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM