Fixed Cannot open database requested by the login. The login failed

1

I try to execute this web application but it gave me this error messages when I try to register a user account in the web application:

System.Data.SqlClient.SqlException occurred
HResult=0x80131904
Message=Cannot open database "rentalsystem" requested by the login. The login failed.
Login failed for user 'MicrosoftAccount\corene100@outlook.com'.
Source=.Net SqlClient Data Provider

I look up online and try any of the solutions stated but still this error pops up every time I try to click the register button. I already created a user login for MicrosoftAccount\corene100@outlook.com (using Windows authentication) in Microsoft SQL Server Management Studio and confirm that it has db_owner permissions to the database.

However, if I try to create the login for SQL Server Authentication, the login name is not available because of the special character existed. I have connect a lot of other database before but none of this error pops up ever.

Is there any way to let the Visual Studio 2017 connect to database using my original user login credentials? Which is DESKTOP-2UB7OKA\Corene. I have tried to change the connection string to this too:

Data Source=DESKTOP-2UB7OKA;Initial Catalog=rentalsystem;
Integrated Security=True;Pooling=False;User ID=MicrosoftAccount\corene100@outlook.com

or

Data Source=DESKTOP-2UB7OKA;Initial Catalog=rentalsystem;
Integrated Security=True;Pooling=False;User ID=DESKTOP-2UB7OKA\Corene

None of those works. And the second one still make it login to database using the MicrosoftAccount\corene100@outlook.com username.

What is the problem here? I have confirm both user have the db_owner permission to the database and I have enabled the Windows Authentication on the web application properties. I have no idea what's next I have to do.

Please help, thanks.

c#
asp.net
sql-server
visual-studio
sqlexception
asked on Stack Overflow Apr 2, 2017 by Corene • edited Apr 2, 2017 by Corene

3 Answers

2

I had this problem and what solved it for me was to:

  • Go to the Application pools in the IIS
  • Right click on my project application pool
  • In Process Model section open Identity
  • Choose Custom account option
  • Enter your pc user name and password.
answered on Stack Overflow Feb 28, 2018 by AH Rasel
1

In your Visual Studio go to "SQL Server Object Explorer". (if you don't see it go to View in the menu bar and click on SQL Server Object Explorer), you need select your database, right click and then click on Detach.

hope this will help. Thanks

answered on Stack Overflow Oct 25, 2018 by user2662006
0

Please ensure the database name is specified correctly in connection string. I had a typo, and got the error.

answered on Stack Overflow May 8, 2020 by Roman O

User contributions licensed under CC BY-SA 3.0