I have created a database in Azure and connected it in SSMS, but when I try to scaffold it in Visual Studio I always get the same error which says:
login failed for 'user'.
Any tips on how I can successfully scaffold it?.
I tried disconnecting and reconnecting it again, and I also changed my login details and I still get the same error.
When I tried to reproduce your requirement in my environment, I got the same error login failed for user "username"
.
Steps to fix the issue:
Connect to data base
instead of default.Tools=>Connect to database
, check if the Test connection is Successful or not.Finally, Run the below given Scaffolding command in Package Manager
console in Visual Studio
.
Scaffold-DbContext "Server=tcp:<yourservername>.database.windows.net,1433;Initial Catalog=<your_database_name>;Persist Security Info=False;User ID=<User_name>;Password=<your_newly_created_password>;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
Model classes has been generated as shown below: