How to attach a database?

deletedT

Guest
Local time
Today, 23:47
Joined
Feb 2, 2019
Messages
1,218
I'm trying to attach a database in SQL Server Management, but I'm receiving this error.

2020-04-21_0-21-57.jpg


I right clicked Databases and select Attach from menu. As soon as I select the mdf file I receive this error.
Any kind of help is much appreciated.

Edit: The sentence in Japanese means : Access is denied.
 
Hi Tera,

I suspect you do not have creation rights. You might have an existing DB that you can edit, but you might not be able to create a NEW one. Hope this makes sense.
 
Hi Tera,

I suspect you do not have creation rights. You might have an existing DB that you can edit, but you might not be able to create a NEW one. Hope this makes sense.
I have full rights over the server. Just tried and was able to add new databases.

Thanks
 
Thanks for thinking loud.
Since the database is not attached , it's not listed in Databases. Should I create a new Database and import from backup?

Thanks
 
Sorry I am not an expert and hopefully someone will chimes in. But I have gone this route back in the day.

1587398489985.png
 
Thanks. Will try to see what happens.
Meanwhile I posted a question in General forum. I appreciate if you take a look there too.

thanks again.
 
When you say attach I'm not sure I understand what you are trying do.
is the MDF file in use? You might need to take it offline.
Can you take a back up and restore it to your server?
 
I take a backup every 6 hours.

This is the long story.
I had to add several major and critical changes to a database in sql server. This changes needed several design changes in main tables.
I tried to use ...Copy Database .... to make a copy of the database and work on the copy first as a test.
While Sql Server Management was trying to copy the database, I received an error message telling Management studio failed to copy the database.
Well...with this error, the database was gone.
Since the mdf file stills exists, I was trying to attach it again.

Hope it makes sense
 
I'm answering on my tablet so don't have SQL Server available to give details at the moment
Normally you would restore from a .BAK file not the .MDF and from memory you have to do 'restore with replace'.
 
I know hindsight is always simple after the event, but you should probably have simply restored the backup to a new database name as a development copy, tested on that and then scripted your changes.
From your description, I'm not sure the MDF file will be in a suitable state to attach as it wasn't probably detached in the first place.
 
I'm answering on my tablet so don't have SQL Server available to give details at the moment
Normally you would restore from a .BAK file not the .MDF and from memory you have to do 'restore with replace'.
I wasn't going to restore. I intended to attach a .mdf file to a sql server.
Thanks.
 
I know hindsight is always simple after the event, but you should probably have simply restored the backup to a new database name as a development copy, tested on that and then scripted your changes.
From your description, I'm not sure the MDF file will be in a suitable state to attach as it wasn't probably detached in the first place.

Well, I ended up to do the same.

Thanks
 
Bit late to the party here, but that attach DB error looks to be folder level permissions or invalid path.
 

Users who are viewing this thread

Back
Top Bottom