Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot open database requested by the login. The login failed. Login failed for user

I have copied a DB from one my computers and using it here. On trying to open the page which requires the fetching content from DB, on con.open I am getting this exception:

Unable to open the physical file "E:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\cakephp.mdf". Operating system error 32: "32(The process cannot access the file because it is being used by another process.)". Unable to open the physical file "E:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\cakephp_log.LDF". Operating system error 32: "32(The process cannot access the file because it is being used by another process.)". Cannot open database "cakephp" requested by the login. The login failed. Login failed for user 'Sarin-PC\Sarin'.

I have attached the database from Management Studio Express 2008 and I have also checcked the connection string. Here it is:

<connectionStrings>
        <add name="cn" connectionString="server=.\sqlexpress;database=cakephp;integrated security=true;uid=sarin;pwd=******"/>
    </connectionStrings>

In Visual Studio, when I test the connection, it says "Test connection succeeded". However, there is one strange thing going on. When I login to the Management Studio, there is no + sign with the newly attached database, as shown.

alt text

If the full WebConfig is reqiured to be seen, I have pasted it here: http://pastebin.com/sVAuN0Ug

like image 820
Cipher Avatar asked Jan 15 '11 09:01

Cipher


1 Answers

There are users of the database, but, there are also users of the server. One user has to have login rights to SqlServer before it can use the database.

In your case you copied the database and it's users, but those users don't have login permissions on the new server. Solution would be to add a new Login account on SqlServer (go to the Security node of the SqlServer, not the Security node of the database), and add it there. When you add that user, assign it to the database as well, and that should work.

Edit: After reading your issue further, is it possible that there are two sql servers targeting the same mdf file? Because that cannot work. Also, when copying database files, have you detached them before copying? If that's all fine, then try making backup and then restore.

like image 184
veljkoz Avatar answered Sep 18 '22 13:09

veljkoz