System.Data.SqlClient.SqlError: There is already an object named 'sysnsobjs' in the database. (Microsoft.SqlServer.Express.Smo) - sql-server

I am getting SQL restore error , please help.
Im using Managment studio. Im trying to restore my database(say for example database name XYZ) taken backup from SQL 2000 server and trying to restore to 2008 R2 database XYZ. The exact error string is during Restore failed is
Restore failed for Server 'MACHINENAME\INSTANCENAME'. (Microsoft.SqlServer.SmoExtended)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.50.1617.0+((KJ_RTM_GDR).110422-1125+)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Restore+Server&LinkId=20476
Program Location:
at Microsoft.SqlServer.Management.Smo.Restore.SqlRestore(Server srv)
at Microsoft.SqlServer.Management.SqlManagerUI.SqlRestoreDatabaseOptions.RunRestore()
===================================
System.Data.SqlClient.SqlError: There is already an object named 'sysnsobjs' in the database. (Microsoft.SqlServer.Smo)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.50.1617.0+((KJ_RTM_GDR).110422-1125+)&LinkId=20476
Program Location:
at Microsoft.SqlServer.Management.Smo.ExecutionManager.ExecuteNonQueryWithMessage(StringCollection queries, ServerMessageEventHandler dbccMessageHandler, Boolean errorsAsMessages)
at Microsoft.SqlServer.Management.Smo.BackupRestoreBase.ExecuteSql(Server server, StringCollection queries)
at Microsoft.SqlServer.Management.Smo.Restore.SqlRestore(Server srv
ODBC SQL server Driver ERROR There is a already an object named
'sysnobjs' in database
While restoring SQL Server 2000 user database to SQL Server 2008 R2 version.
Please let me know whether Microsoft SQL Server 2000 database backup and restore it to SQL Server 2008 is allowed?
If it is not so , is there any work-around for this issue?

In options, while you are in the box that has you choose where your backup is to restore, choose overwrite existing database option. That should get rid of that error and allow you to restore that backup.

After selecting the Backup File to restore in the General Tab, Go to the Options Tab.
Select "Överwrite the existing database (WITH REPLACE)"
Then, in the "Restore the database files as:" Table, Go to the [Restore As] column
Notice the string in the first row (for Data) and the string in the second row (for Images) are exactly the same. This will result in some errors.
Change the string in the first row to something else (like adding a date), for example
C:................\YourFileName.mdf
C:................\YourFileName20151124.mdf
Problem solved
Here's my full Script:
RESTORE DATABASE [Makhado_Indigents] FROM DISK = N'C:\IndiCheck\Makhado_Indigents.bak'
WITH FILE = 1, MOVE N'New_Indigents'
TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.INDICHECK\MSSQL\DATA\Makhado_Indigents.mdf',
MOVE N'New_Indigents_Images'
TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.INDICHECK\MSSQL\DATA\Makhado_Indigents1.mdf',
MOVE N'New_Indigents_log'
TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.INDICHECK\MSSQL\DATA\Makhado_Indigents.ldf',
MOVE N'New_Indigents_Docs'
TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.INDICHECK\MSSQL\DATA\Makhado_Indigents.New_Indigents_Docs',
NOUNLOAD, REPLACE, STATS = 10
GO
You may also need to Switch Filestreaming on by running the following script:
EXEC sp_configure filestream_access_level, 2 RECONFIGURE
Restart the server:
Start > All Programs > Microsoft SQL Server 2008 R2 > Configuration Tools > SQL Server Configuration Manager
Right Click on the Server and select Restart

Related

Restoring back up file is failed (on device xx.bak is incorrectely formed and cannot be read

I am using a SQL server 2016 and trying to restore my bakup file with new database. But Its showing the below message "on device xx.bak is incorrectely formed and cannot be read".
This is the Restore statement that I am using :
RESTORE DATABASE TESTDB FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Backup\DEMO_clone.bak' WITH FILE = 38, NOUNLOAD, REPLACE, STATS = 5`
The backup path suggests you are trying to restore SQL Server 2016 database backup. You cannot restore a backup made from a later SQL Server version to an earlier version.

SQL Server database restore error: specified cast is not valid. (SqlManagerUI)

I am using SQL Server 2008 R2 Standard (version 10.50.1600.1) for my production website and
SQL Server Express edition with Advanced Services (v10.50.1600.1) for my localhost as a database.
Few days back my SQL Server crashed and I had to install a new 2008 R2 Express version on my localhost. It worked fine when I restored some older versions taken from Express edition but when I try to restore database from .bak file which is taken from production server it is causing the following error:
Error: Specified cast is not valid. (SqlManagerUI)
and when I try to restore the database using command
Use Master
Go
RESTORE DATABASE Publications
FROM DISK = 'C:\Publications.bak'
WITH MOVE 'Publications' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS2008R2\MSSQL\DATA\Publications.mdf',--adjust path
MOVE 'AlPublications_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS2008R2\MSSQL\DATA\Publications.ldf'
It generates a different error
Msg 3154, Level 16, State 4, Line 1
The backup set holds a backup of a database other than the existing 'Publications' database.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
I have cross checked the versions. They all seem matching to me as shown in the image below
Previously I was able to restore a database from standard version to express edition but now it fails. I deleted the database and tried to recreate it. That fails, too.
I am not sure what I am doing wrong. I would appreciate help in this regarding
Issue was resolved as it seems .bak file was corrupt. When I tried it with a different file it worked.
Could be because of restoring SQL Server 2012 version backup file into SQL Server 2008 R2 or even less.
The GUI can be fickle at times. The error you got when using T-SQL is because you're trying to overwrite an existing database, but did not specify to overwrite/replace the existing database. The following might work:
Use Master
Go
RESTORE DATABASE Publications
FROM DISK = 'C:\Publications_backup_2012_10_15_010004_5648316.bak'
WITH
MOVE 'Publications' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS2008R2\MSSQL\DATA\Publications.mdf',--adjust path
MOVE 'Publications_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS2008R2\MSSQL\DATA\Publications.ldf'
, REPLACE -- Add REPLACE to specify the existing database which should be overwritten.
Finally got this error to go away on a restore. I moved to SQL2012 out of frustration, but I guess this would probably still work on 2008R2. I had to use the logical names:
RESTORE FILELISTONLY
FROM DISK = ‘location of your.bak file’
And from there I ran a restore statement with MOVE using logical names.
RESTORE DATABASE database1
FROM DISK = '\\database path\database.bak'
WITH
MOVE 'File_Data' TO 'E:\location\database.mdf',
MOVE 'File_DOCS' TO 'E:\location\database_1.ndf',
MOVE 'file' TO 'E:\location\database_2.ndf',
MOVE 'file' TO 'E:\location\database_3.ndf',
MOVE 'file_Log' TO 'E:\location\database.ldf'
When it was done restoring, I almost wept with joy.
Good luck!
Below can be 2 reasons for this issue:
Backup taken on SQL 2012 and Restore Headeronly was done in SQL 2008 R2
Backup media is corrupted.
If we run below command, we can find actual error always:
restore headeronly
from disk = 'C:\Users\Public\Database.bak'
Give complete location of your database file in the quot
Hope it helps

Attach a .MDF file created by SQL Server 2008 in SQL Server 2000

I created a database in SQL Server 2008. I detached the database and I copied the .mdf over to the server, which is running SQL Server Enterprise Manager (SQL Server 2000).
When I try to attach the MDF I get...
Microsoft SQL-DMO (ODBC SQL State: HY000) Error 602: Could not find
row in sysindexes for database ID 13, object ID 1, index ID 1. Run
DBCC CHECKTABLE on sysindexes.
What does this mean? Is this because the db was created in a newer version?
From the documentation on the (I believe depreciated, but used in SQL Server 2000) sp_attach_db stored proc:
A database created by a more recent version of SQL Server cannot be
attached in earlier versions.
I think you'll have to script the schema and data of your database.
Pinal Dave has a good tutorial on how to do this here - just remember to make sure you choose the following settings:
Under General:
Script for server version: SQL Server 2000
Under Table/View options:
Script data: True
Remember to double check the settings for any others you might be interested in, such as foreign keys, triggers etc.
This is do-able, but you'd need to convert it to the SQL 2000 format before detaching it and attaching it on the old server. Here are the steps:
In entreprise manager, right click the database
Choose properties
On the left, click Options
Change the "Compatibility Level" to SQL Server 2000 (80)
Then save, and detach before reattaching on the old server.

Can't attach northwind database to sql server 2008 R2

When I try to I get the following error in SQL Server Management Studio:
TITLE: Microsoft SQL Server Management Studio
Attach database failed for Server 'AHAKEEM'.
(Microsoft.SqlServer.Smo)
ADDITIONAL INFORMATION:
An exception occurred while executing a Transact-SQL statement or
batch. (Microsoft.SqlServer.ConnectionInfo)
Unable to open the physical file "C:\SQL Server 2000 Sample
Databases\northwnd.mdf". Operating system error 5: "5(failed to
retrieve text for this error. Reason: 15105)". (Microsoft SQL Server,
Error: 5120)
This is a fresh version of Northwinds mdf which just came from Microsoft's installer.
Error 5120 is a sharing violation on the file you're opening. Try starting SQL Management Studio as Administrator and make sure that the db isn't attached already.
The error occurs when the mdf or ldf file is missing, if its an ldf we can recreate the same using the below listed scripts:
Method 1: To recreate all the log files
EXECUTE sp_attach_single_file_db #dbname = 'SAMPLEDB',
#physname = N'D:\MSSQL\DATA\SAMPLEDB.mdf'
GO
Method 2: If one or more log files are missing, they are recreated again.
CREATE DATABASE SAMPLEDB ON
(FILENAME = N'D:\MSSQL\DATA\SAMPLEDB.mdf')
FOR ATTACH_REBUILD_LOG
GO
Method 3: If only one file is missing, they are recreated again.
CREATE DATABASE SAMPLEDB ON
( FILENAME = N'D:\MSSQL\DATA\SAMPLEDB.mdf')
FOR ATTACH
GO
I tried to install Northwind and pubs Sample Databases for SQL Server 2000 and attach both databases in SQL Server 2014, and gave me an error because they were compatible version.
These are the steps to successful install the Sample Database in your SQL Server 2014:
After you download the Sample Databases in your PC, then open SQL Server 2014 Management Studio. After successful connection, your SQL Server instance should be listed in the Object Explorer.
Now under File Menu select Open > File.
Find the instnwnd.sql in your computer and select it. Click Open
SQL script should open in the main window.
Do not click on Execute yet. If you do, you will get the following error:
Could not find stored procedure ‘sp_dboption’.
Around the line 20, remove the following two lines:
exec sp_dboption 'Northwind','trunc. log on chkpt.','true' exec
sp_dboption 'Northwind','select into/bulkcopy','true'
Replace them with this line as shown below:
alter database Northwind set recovery simple
To attach 'pubs' database, repeat the step 2 above and this time open instpubs.sql file. Replace the sp_dboption as you did before with:
alter database Pubs set recovery simple
All that is left is to execute the script, so click on Execute in both scripts.
Note: the folder location for your sample database by default is "C:\SQL Server 2000 Sample Databases"

Create/restore database from backup SQL Server Express

I don't have SQL Server Management Studio on my machine.
I have a database backup (SQL Server 2008 R2). There is SQL Server Express that installed with Visual studio 2010 ultimate installed on my machine.
How can I restore this back up on a database and attaching it to SQL Server Express?
Is there any solution wihout using SQL Managment Studio Express ?
Even with SQL Server Management Studio Express, you won't be able to restore this backup. The Express edition being installed with Visual Studio 2010 is version 2008 of SQL Server - your backup is one from a SQL Server 2008 R2 release - those backups cannot be restore onto a 2008 version.
You will need to download the SQL Server 2008 R2 Express version, and while you're at it - get the version with the Management Studio! Install this, and then you'll be able to restore your database backup.
If you really really want to restore your database without using Mgmt Studio - you can of course use a RESTORE statement in T-SQL and run this using the sqlcmd command line tool:
RESTORE DATABASE YourDatabaseName
FROM DISK = N'(path to your BAK file)'
WITH FILE = 1,
MOVE N'(your DB name)' TO N'(your SQL path)database.MDF',
MOVE N'(your DB name)_LOG' TO N'(your SQL path)database_LOG.LDF',
NOUNLOAD,
REPLACE,
STATS = 10
GO
(and of course, there's also a BACKUP command which you can use in a similar fashion - the MSDN Books Online are your friend for details about the syntax!!).
Late one but hopefully useful to others who are viewing this….
If the problem is restoring without management studio this can be easily solved by using sqlcmd as marc_s already pointed out.
However if the real problem is restoring 2008 R2 backup on SQL 2008 without using SSMS then only solution is using third party tools that can read backup and generate scripts for creating schema and inserting data.
Idea is to create empty database on SQL 2008 and use a third party tool to compare it to backup generated with 2008 R2.
I’ve used ApexSQL Diff and ApexSQL Data Diff with good success in my previous job but there are also good tools from Red Gate (SQL Compare) and Idera (Comparison toolset). If you look up online you’ll probably find a lot more….
Disclaimer: I’m not affiliated with any of the companies mentioned above…
Why don't you get SQL Managment Studio Express? It is free, and should allow you to administer local sql express instances.
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=c243a5ae-4bd1-4e3d-94b8-5a0f62bf7796
BACKUP DATABASE [AdventureWorks] TO
DISK = N'\\nas\Backup\L40\SQL2005\AdventureWorks_backup_200702120215.bak'
WITH NOFORMAT, NOINIT, NAME = N'AdventureWorks-Full Database Backup',
SKIP, NOREWIND, NOUNLOAD, STATS = 10
RESTORE DATABASE [AdventureWorksNew]
FROM DISK = N'\\nas\Backup\L40\SQL2005\AdventureWorks_backup_200702120215.bak'
WITH FILE = 1,
MOVE N'AdventureWorks_Data' TO N'C:\Data\MSSQL.1\MSSQL\Data\AdventureWorksNew_Data.mdf',
MOVE N'AdventureWorks_Log' TO N'C:\Data\MSSQL.1\MSSQL\Data\AdventureWorksNew_Log.ldf',
NOUNLOAD, STATS = 10
Following link provides similar solution as marc_s, and it goes even deeper. I was able to successfully create a new DB from Backup file with the solution provided in the link below.
http://codeonaboat.wordpress.com/2012/02/16/sql-server-2008-creating-a-database-from-a-bak-file/
The solution below is copied from above link:
In SSMS, open a query window in the master database of the database server. That’s where you will run the following queries.
See what the “LogicalName” of the database that has been backed up in the .bak file is
RESTORE FILELISTONLY FROM DISK =
'c:\DatabaseBackups\dev2012021601.bak'
This will give you the logical name of the database and its associated log file. Lets assume that the names are “dbname” and “dbname_log”
Now run the following restore command. Make sure that a database with the name you are trying to create doesn’t already exist (in the code sample below, dbForSocialMigration doesn’t exist).
RESTORE DATABASE dbForSocialMigration
FROM DISK = 'c:\DatabaseBackups\dev20120307.bak'
WITH
MOVE 'dbname' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\dbForSocialMigration.mdf',
MOVE 'dbname_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\dbForSocialMigration_log.mdf'
C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA is the directory where SQL Express usually keeps its data files. You can find the directory your database server is using by selecting a database from it, right clicking and opening the properties dialog and selecting the “Files” option from the left.
That should work, and at that point you should be able to access the database “dbForSocialMigration” populated with all the tables and data from the .bak file.

Resources