I have created a web service which is saving some data into to db. But I am getting this error:
Cannot open database "test" requested by the login. The login failed. Login failed for user 'xyz\ASPNET'.
My connection string is
Data Source=.\SQLExpress;Initial Catalog=IFItest;Integrated Security=True
I found that I also had to set the UserMapping option when creating a new login and this solved the problem for me. Hope that helps anyone that also found themselves stuck here!
Edit: Setting the login as db owner solved the next problem, too
Some times this trouble may appear if you open this db in another sql server (as example, you launch sql managment studio(SMS) and add this db), and forget stop this server. As result - you app try to connect with user already connected in this db under another server. To fix that, try stop this server by Config. dispatcher sql server.
My apologies about bad english. Kind regards, Ignat.
I had this problem and what solved it for me was to:
I tried to update the user, and it worked. See the command below.
Just replace
user('ftool')
accordingly.I'd go for the 2nd option: the error message implies the default database is either not there or no rights in it, rather than not set up as a login.
To test if it's set up as a login
If NULL
If not NULL
If NULL
I used Windows authentication to connect to local database .mdf file and my local server was sql server 2014. My problem solved using this connection string: