Reputation: 438
I've seen this question asked many times before, but they were always targetting the older means of adding connection strings through the App.config files.
I am using an asp.net Core 3.1 Web application which uses the appsettings.json to create a connection string. Which is as follows:
"ConnectionStrings": {
"DefaultConnection": "Server=WS-NAME;Database=BookListRazor;User ID=sa;Password=****;Trusted_Connection=True;MultipleActiveResultSets=True"
},
I have tried using this SSMS login, but I also tried creating a new one that wasn't sa. Both these users have dbcreator, public & sysadmin server roles enabled.
When I try create the database manually using SSMS, it works perfectly fine. Whereas when I use the same login details as part of my connection string, I am returned with the error
CREATE DATABASE permission denied in database 'master'.
I have tried many different ways that're suggested as solutions for this but none seemed to work. I'd appreciate any suggestions you guys may have.
Thank you in advance!
Upvotes: 0
Views: 1172
Reputation: 89361
This User ID=sa;Password=****;Trusted_Connection=True
is wrong. You set Trusted_Connection to False when passing a User ID and Password. Otherwise the Windows identity of the client program is used to connect to the SQL Server
From Docs:
If User ID and Password are specified and Integrated Security is set to true, the User ID and Password will be ignored and Integrated Security will be used.
SqlConnection.ConnectionString
Upvotes: 5