What Causes SQL Server To Gets Stuck in Restored State - sql-server

The company I work for will usually have a personal database for us that is a clone of the staging database. Sometimes I will need to blow away my database and restore it to the current version of the staging database, so the process by which I do this is:
Open SQL Server Management Studio
Connect to the server
Open the Object Explorer
Expand the server tree node
Expand the Databases tree node
Right-click on my database
Click Delete (check the Close existing connections options)
Click OK
Right-click on the Databases tree node
Click Restore Database...
In the source database dropdown, select the staging copy
In the destination database combobox, change the value to be the name of my database
Click OK
The issue is that more often than not, the database gets stuck in a restored state. The issue is simple enough to resolve in that I can run the following query immediately following step 13:
RESTORE DATABASE stagingdatabase WITH RECOVERY;
But preferably I'd like to know why it gets stuck in the restored state to begin with and see if there is something I can add to my list of steps to prevent it from getting stuck in the first place.

Related

Restore SQL Server database

I'm attempting to restore a SQL Server database that was on one server to a new server via SSMS. I right-click on Databases and select Restore Database....
From the Restore Database window, I select the Device radio button and add my .bak file to the Backup media list using the "Add" button. If I click the "Contents" button, everything looks great. The contents window shows all the info about the back such as the database name, the fact it was a full backup, the server name it was backed up from, username, etc... So, I know the backup file is valid.
However, when I return to the Restore Database screen from the Select Backup Device window, nothing shows in the "Backup sets to restore:" grid and the OK button is disabled. So, I'm not able to restore the backup.
I'm not sure what version of SQL Server I'm coming from but the destination version is 11.0.6579.0

Creating a Copy of a Database inside the same machine using Backup/Restore is rasing an errror :- The backup set holds a backup of a database

I want to create a copy of my sql server 2008 r2 database (named ERP) inside the same machine. so I did the following steps:-
I right click on the original database ERP and I select Tasks>>Backup.
then I create a new empty database named "ERP_Copy".
I right click on the ERP_Copy database, then select restore>>database.
inside the restore options I define the To to be ERP_Copy and the From to be ERP.
then I click to start the process, but I got the following error :-
so can anyone advice on these 2 questions:-
what is causing this error ?
could my original database ERP got corrupted or modified due to the error ?? or my ERP should not be modified by my above operation and the error I got ?
Thanks
the error is as stated in the message: you are restoring on a target database that is not the one used as the backup source.
To solve and complete the restore, start the restore, go to the Options page and tick the Overwrite the existing database (WITH REPLACE) checkbox.
DOUBLE CHECK source and destination database because the above checkbox would completely smash your production db if you make the wrong choices...
The original database has not been altered by the first (failed) operation.

How to import a bak file into SQL Server Express

I have a .bak file, and I want to use this file to recreate the database in a fresh install of SQL Server 2008 Management Studio.
Can someone point me in the right direction on how this can be done?
I have tried:
right click on the Databases container within object explorer
from context menu select Restore database
Specify To Database as either a new or existing database
Specify Source for restore as from device
Select Backup media as File
Click the Add button and browse to the location of the BAK file
but I am getting error that
Restore failed for Server 'MyServer-PC'. (Microsoft.SqlServer.SmoExtended)
ADDITIONAL INFORMATION:
System.Data.SqlClient.SqlError: The backup set holds a backup of a database other than the existing 'invent' database. (Microsoft.SqlServer.Smo)
There is a step by step explanation (with pictures) available # Restore DataBase
Click Start, select All Programs, click Microsoft SQL Server 2008 and select SQL Server Management Studio.
This will bring up the Connect to Server dialog box.
Ensure that the Server name YourServerName and that Authentication is set to Windows Authentication.
Click Connect.
On the right, right-click Databases and select Restore Database.
This will bring up the Restore Database window.
On the Restore Database screen, select the From Device radio button and click the "..." box.
This will bring up the Specify Backup screen.
On the Specify Backup screen, click Add.
This will bring up the Locate Backup File.
Select the DBBackup folder and chose your BackUp File(s).
On the Restore Database screen, under Select the backup sets to restore: place a check in the Restore box, next to your data and in the drop-down next to To database: select DbName.
You're done.
To do this via TSQL (ssms query window or sqlcmd.exe) just run:
RESTORE DATABASE MyDatabase FROM DISK='c:\backups\MyDataBase1.bak'
To do it via GUI - open SSMS, right click on Databases and follow the steps below
Using management studio the procedure can be done as follows
right click on the Databases container within object explorer
from context menu select Restore database
Specify To Database as either a new or existing database
Specify Source for restore as from device
Select Backup media as File
Click the Add button and browse to the location of the BAK file
refer
You'll need to specify the WITH REPLACE option to overwrite the existing adventure_second database with a backup taken from a different database.
Click option menu and tick Overwrite the existing database(With replace)
Reference
I had the same error. What worked for me is when you go for the SMSS GUI option, look at General, Files in Options settings.
After I did that (replace DB, set location) all went well.
Restoring a Database from Backup
sql-server-->connect to instance-->Databases-->right-click on databases-->Restore
DataBase..-->Device-->Add-->choose the path_filename(.bak)-->click OK

restore .bak mssql 2005 to a new a server of mssql 2008r2

I created a .bak file (backup) from server A with the with following specs: Windows server 2003, MSSQL 2005. Now I would like to restore this backup on a new Server B with the following specs: Windows 8, MSSQL 2008 R2. I did the following to try and do the restore
Copy files to the new server(Server B)
Clicked on Microsoft SQL Server Management Studio 2008R2(Server B)
Right click on Databases to create a new Database called Boom (Server B)
After creating the new Database(Boom), right clicked on Tasks->Restore->Database and
On the source for restore area, Clicked From device and located the .bak file, select it and cliked ok.
Instead of getting the success message, I get the following error:
Restore failed for Server 'Server B'.(Microsft.SqlServer.SmoExtended)
Additional information: System.Data.SqlError: The backup set holds a backup of a database other than the existing 'Boom' database(Microsoft.SqlServer.Smo).
Please assist, Im am new to MSSQL
Right click on Databases to create a new Database called Boom (Server B)
After creating the new Database(Boom), right clicked on Tasks->Restore->Database and
Well now you're making a new database and trying to overwrite it with a different database's backup. Hence:
The backup set holds a backup of a database other than the existing 'Boom' database
There's a WITH REPLACE option that allows you to proceed, but just avoid the indirection to begin with: restore the database, don't make a new one.
You'll probably need to delete the redundant Boom database you made, first. If, for whatever reason, you couldn't delete the database you'd have to use WITH REPLACE.
"Restore failed for Server 'Server B'.(Microsft.SqlServer.SmoExtended) Additional information: System.Data.SqlError: The backup set holds a backup of a database other than the existing 'Boom' database(Microsoft.SqlServer.Smo)."
I encountered this error when the logical name of the files do not match. Check on the logical name of the database you backed up and you will need the same logical name for the new database you created.
Or you can surely use the With Replace option too as specified by ta

How Do I Copy and Overwrite a Database in SQL Server 2005 with SSIS?

I HAVE to be missing something really simple here!
I have a database in my development environment called Project.
I have a database in my test environment called Project_UAT.
I've created an SSIS package that successfully copied my database from Project to Project_UAT. I'm pretty sure this eliminates most permission and configuration issues.
Now, I want to re-create the package and this time allow it to overwrite the destination, which is Project_UAT. This is simply because from time to time I want to click a button in the Microsoft SQL Management Studio that pushes the new database schema, data, users, and everything, out to my testing environment. I WANT to overwrite the data.
So I create the package just like I did before, but this time I specify the already-existing database name as the "Destination database" and I select the radio button called "Drop any database on the destination server with the same name, then continue with the database transfer, overwriting existing database files."
I click Next, and what does it tell me?
"Database name already exists at destination"
Well, I KNOW! I just told you I want to overwrite it!
How do I make this work?
Not sure if I am missing the point but why do you not use a task to drop/delete the existing database prior to your deployment step?
Perhaps you could qualify the SSIS Component Tasks you are using within your SSIS package.
Cheers, John
You can add an Execute SQL Task into the Control Flow to drop the database. Just set the SQLStatement property to
DROP DATABASE Project_UAT
After this step is executed the new copy of the Project_UAT database won't have to overwrite the old one.
I had this problem because I deleted the database before hand. The database is not in the destination folder, but SQL Server 2008 still thinks it is there. Refresh didn't work. And SQL Server wouldn't honor the selection of "Drop any database on the destination server..." It just complained that the database already existed.
Guys this is a common sense solution. A lot of complexity for nothing.
Backup the destination database you want to copy to and delete the destination database.
Open the copy database wizard and follow the steps.
Use the detach and attach method.
When you get to the configure destination database use the option if destination database exists select drop database on destination server with same name.
Now it will continue to the next screen.
But this only works if you delete the destination database first before starting the wizard.
I may have missed something but this worked for me.

Resources