Thursday, March 8, 2012

Database restore to new database

Hello all,

I am using SQLDMO to try and restore a database to a 'new' database. I am using the relocatefiles property and setting it correctly, but when I restore I always get the error:

"[Microsoft][ODBC SQL Server Driver][SQL Server]Logical file 'OLDDATABASENAME' is not part of database 'NEWDATABASENAME'. Use RESTORE FILELISTONLY to list the logical file names.
[Microsoft][ODBC SQL Server Driver][SQL Server]RESTORE DATABASE is terminating abnormally."

My code is set up like this:

restoreObject.RelocateFiles = "[oldDbName],[C:\newDbName.mdf],[oldDbName],[C:\newDbName.ldf]";

Any ideas? Can I assume the logical file is the same as the 'old' database name?

When I try and use the 'readfilelist' function to get the list of logical filenames, I always get empty results.

what are the logical filenames of your new database?

they must match the logical filenames from the backup.

hope this helps

|||

you can use readfilelist function to read the logic file name

for example: your "oldDbName" may be "oldDbName_data" and "oldDbName_log"

but i found the function is failure in SQL SERVER 2005 EXPRESS, i don't know why....

No comments:

Post a Comment