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.

Sivvie Lim
  • 784
  • 2
  • 14
  • 43
  • Are you sure above users are connecting in SSMS? – shaair Apr 02 '17 at 06:30
  • If you have `Integrated Security=True` in your connection string, then the code will try to log in with **your currently logged in Windows user** - no matter what other `User Id=...` you also specify in your connection string. If you want to specify a **specific** SQL Server user account and use that to log in, you must **disable** the "integrated security" – marc_s Apr 02 '17 at 07:57
  • @marc_s I set the `Integrated Security=false`, apparently is was able to login but then this error pops up : `A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.)` I am using the `User ID=DESKTOP-2UB7OKA\Corene` User ID. – Sivvie Lim Apr 02 '17 at 08:26
  • @SAL Yes I checked the SSMS, both users are there and are db_owner to the database. – Sivvie Lim Apr 02 '17 at 08:34
  • I mean not just exist it is connecting with windows authentication?Because first you have sure in SSMS UI and after that we can check the work around. – shaair Apr 02 '17 at 09:21
  • Possible duplicate of [Cannot open database "test" requested by the login. The login failed. Login failed for user 'xyz\ASPNET'](http://stackoverflow.com/questions/2575907/cannot-open-database-test-requested-by-the-login-the-login-failed-login-fail) – VDWWD Apr 02 '17 at 09:30
  • @SAL yes it is when I first open the SSMS, it is connected with `DESKTOP-2UB7OKA\Corene` in Windows Authentication. – Sivvie Lim Apr 02 '17 at 09:31
  • @VDWWD I have tried the solutions in that link, that's the first link I found when I search on internet before I ask this question. – Sivvie Lim Apr 02 '17 at 09:40
  • [Login failed for user 'DOMAIN\MACHINENAME$'](http://stackoverflow.com/questions/2806438/login-failed-for-user-domain-machinename) will help you. Becuase lot of factors behind this issue. May from **IIS** Or **web.config** or **Integrated Security**. But you have to check all scenarios. – shaair Apr 02 '17 at 10:18
  • @SAL Thanks I found the problem, turns out I have to create a user using SQL Authentication to login. Thanks for the help!! – Sivvie Lim Apr 02 '17 at 11:04
  • Well similar question was already asked. Please have a look at the following link http://stackoverflow.com/questions/2575907/cannot-open-database-test-requested-by-the-login-the-login-failed-login-fail. If it works please reply back. Thank you. – Santhosh kumar Vadlamani Apr 02 '17 at 03:40

4 Answers4

7

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

Roman O
  • 3,172
  • 30
  • 26
3

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.
AH Rasel
  • 161
  • 2
  • 15
2

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

user2662006
  • 2,246
  • 22
  • 16
  • Weirdly enough, this helped me. I think the error came because I was duplicating the project folder.. detaching them seemed to work.. – Franck E Feb 27 '21 at 09:10
2

In my case, I inherited a project, and got this problem when trying to use the solution on my dev machine. I'm using Integrated Security = False. There was nothing wrong with the login username or password, but I was still getting this error.

It turns out that the connection string had multipleactiveresultsets=True. I removed it just out of desperation, and then I was able to connect. Then I put it back, and it continued to work.

Hope it helps someone!

Sandra
  • 608
  • 2
  • 11
  • 23