you need to give the user "DESKTOP-KRBN07G\juan_" access to the database. I assume you are running VS as admin, which gives you back door access.
Cannot open database requested by the login - "Error Number:4060,State:1,Class:11"
I have an ASP.NET app, and when I launch the app and try to list items from a table by accessing the corresponding route, I get this error: SqlException: Cannot open database "appointments" requested by the login. The login failed. Login failed for user 'DESKTOP-KRBN07G\juan_'.
The database exists, and so do all the tables. I can connect to the database from SSMS and the 'Server Explorer' view in Visual Studio. I am using the connection string provided by the Server Explorer in Visual Studio. I also did a clean installation of Windows, Visual Studio, SQL Server, and SSMS. Currently, I have only one DB server and one database.
My VS and connection string:
And finally the error:
Please help me; this error is driving me mad. If you need any extra info, please let me know.
EDIT 1: I forgot to mention that I disabled my Windows firewall.
2 answers
Sort by: Most helpful
-
-
Juan Jose Herrera 0 Reputation points
2024-09-14T21:39:36.9466667+00:00 Well, guys, I found the problem, it was a wrong and 'hidden' Connection String.
I created a new database with a different name, but the error in the browser after launching the app in my localhost kept pointing to the old database name.
After that, I searched for the old database name throughout the project and discovered that my colleague had added a partial class inside the DataAccess project of the ASP.NET application, which runs in development mode and contains his connection string.
I changed that, and now everything is working fine. All I knew was that the connection string should be in Program.cs or appsettings.json, and no other places.
Thank you all for your time..¡