简体   繁体   中英

Unable to connect to Azure SQL database from my ASP.NET Core Web API application but able to connect to db from Management Studio

I am trying to connect to my Azure SQL database from a ASP.NET Core Web API application. Though I am able to successfully connect to azure db with same credential from SQL Server Management Studio, I keep getting this error:

Cannot open database '', requested by the login'. The login failed. Login failed for user ''

Here is the connection string in my appsettings.json :

"DatabaseConfiguration": {
    "ConnectionString": "Server=tcp:xxx.database.windows.net,1433;Initial Catalog=back-end-sqldb;Persist Security Info=False;User ID=<userid>;Password=<pwd>;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
}

I also tried with

"ConnectionString": "Data Source=server.database.windows.net;Initial Catalog=enrolment--back-end-sqldb;User ID=<userid>;Password=<password>;"

Can anyone help me how to solve this?

Thanks

It worked, when i tried the following connection string with servername along with userid ie

"ConnectionString": "Data Source=server.database.windows.net;Initial Catalog=sqldb;User ID=<userid@server.database.windows.net>;Password=<pwd>;"

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