Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Why uSoft sucks today.

For the last month I've been rewriting, on and off my web site. I say on and off because I get so damned frustrated at times that I throw my hands up and go do something else.

Anyway I'm using an local attached DB, been using it for the last month without problems. SSMS hooks up to it fine, LinqPad hooks up to it fine, VS2013 hooks up to it fine. So today I attach to it using SSMS and I;
1) Run the following query; ALTER DATABASE [aspnet-JaxCoderV20-20150206021315] SET OFFLINE WITH ROLLBACK IMMEDIATE
2) Then I do a Tasks=>Detach

Now I can't get into with anything anyway, locked tighter then a drum.

Just for the heck of it I went into SSMS and did the query; ALTER DATABASE [aspnet-JaxCoderV20-20150206021315] SET OFFLINE WITH ROLLBACK IMMEDIATE
and got;
Msg 5011, Level 14, State 5, Line 1
User does not have permission to alter database 'aspnet-JaxCoderV20-20150206021315', the database does not exist, or the database is not in a state that allows access checks.
Msg 5069, Level 16, State 1, Line 1
ALTER DATABASE statement failed.

and trying to do a query in LinqPad I get;
Unable to open the physical file "J:\WebSites\Web MVC Projects\JaxCoderV20\JaxCoderV20\App_Data\aspnet-JaxCoderV20-20150206021315.mdf". Operating system error 5: "5(Access is denied.)".
An attempt to attach an auto-named database for file J:\WebSites\Web MVC Projects\JaxCoderV20\JaxCoderV20\App_Data\aspnet-JaxCoderV20-20150206021315.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

VS2013 will attach to it and shows the data but when I try to run it I get a;
The underlying provider failed to open.
{"Unable to open the physical file \"J:\\WebSites\\Web MVC Projects\\JaxCoderV20\\JaxCoderV20\\App_Data\\aspnet-JaxCoderV20-20150206021315.mdf\". Operating system error 5: \"5(Access is denied.)\".\r\nCannot attach the file 'J:\\WebSites\\Web MVC Projects\\JaxCoderV20\\JaxCoderV20\\App_Data\\aspnet-JaxCoderV20-20150206021315.mdf' as database 'aspnet-JaxCoderV20-20150206021315'."}

I have Unlocker but it shows that neither the .ldf or the .mdf files are locked.
I rebooted my machine no love there.

Anybody had this problem?
Anybody got a clue, cause I sure as hell don't.
Posted
Comments
Zoltán Zörgő 6-Mar-15 17:40pm    
Try following:
0) You can't do anything as long as it is not attached. You have detached the database.
1) When you log in to SSMS, be sure to have an other database (but not master) as current database when trying to get it back online.
2) If you still don't succeed, restart server instance and log in from command prompt (sqlcmd) so you can issue the set online command. You can use sqlcmd to attach database if you want, but I suppose SSMS will be able to attach.

1 solution

Hi,

This might be your Resolution for SSMS
==================================================

1. You need to be member of sysadmin server role or db_owner database role.

2. Click on the link below to obtain more information:

http://social.msdn.microsoft.com/Forums/en-US/8f4fb67f-c937-408f-859e-fa6ede64bbe2/user-does-not-have-permission-to-alter-database?forum=sqlsecurity

3. Check with your DBA for further assistant with running the upgrade script.

For LinqPad ,try this link
=============================================
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/6dfdcc22-7a81-4e8f-a947-c1ce6982d4b3/flustered-a-database-with-the-same-name-exists-or-specified-file-cannot-be-opened-or-it-is?forum=sqlexpress

For VS2013
================================

I hope this solution helps you

http://www.brainbrushups.com/2013/12/error-attach-database-failed-for-server.html
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900