开发者

Restoring database from another database SMO

How I can restore the database from another database ?

When i do from file restore i do like this:

Restore sqlRestore = new Restore();

 BackupDeviceItem deviceItem = new BackupDeviceItem(filePath, DeviceType.File);
    sqlRestore.Devices.Add(deviceItem);
    sqlRestore.Database = databaseName;

    Server开发者_开发技巧Connection connection = new ServerConnection(serverName, userName, password);
    Server sqlServer = new Server(connection);

    Database db = sqlServer.Databases[databaseName];
    sqlRestore.Action = RestoreActionType.Database;
    String dataFileLocation = dataFilePath + databaseName + ".mdf";
    String logFileLocation = logFilePath + databaseName + "_Log.ldf";


    sqlRestore.RelocateFiles.Add(new RelocateFile(databaseName, dataFileLocation));
    sqlRestore.RelocateFiles.Add(new RelocateFile(databaseName+"_log", logFileLocation));
    sqlRestore.ReplaceDatabase = true;


    sqlRestore.SqlRestore(sqlServer);

But How i can restore from database ? Instead of giving bak file to give database itself as source ?

Thanks.


I think you should probably be looking at the SMO Transfer object instead.

But having said that, the easiest way to copy a complete database is usually to back it up and restore it with a different name. Or you can use the Copy Database Wizard.

See "Copying Databases to Other Servers" in Books Online for more information.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜