Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good Evening Everybody,

Please say how to restore a sql server database (.bak file) using vb.net?


And I am using this code ..
VB
sqlsring = "use master RESTORE DATABASE DBNAME from disk=DBPathName"

But I am getting this error.

"The backup set holds a backup of database other than the existing 'DBNAME' database.
Restore database is terminating abnormally. Changed database context to 'master'"

So Please tell me what is the solution for this error

Thank You.
Posted
Updated 27-Sep-11 15:17pm
v2

1 solution

Try this
SQL
RESTORE DATABASE DBNAME
FROM DISK = DBPathName+'\BackUpYourBaackUpFile.bak'
WITH MOVE 'YourMDFLogicalName' TO DBPathName+'\DataYourMDFFile.mdf',
MOVE 'YourLDFLogicalName' TO DBPathName+'\DataYourLDFFile.ldf'
 
Share this answer
 

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