备份和还原远程sqlserver的smo claase [英] backup and restore smo claases of remote sqlserver

查看:81
本文介绍了备份和还原远程sqlserver的smo claase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在进行数据库备份和还原.

我在按用户位置进行本地服务器备份和还原方面取得了成功,但是当我进行远程服务器数据库备份和还原时,我连接了远程sqlserver并获取了备份,然后将在远程系统而非本地系统上创建备份文件,然后将其还原到数据库中如果我从远程系统中删除该文件然后还原,则将从远程系统还原文件还原.给出异常.

I am working on Database backup and restore.

I have success on local server backup and restore as per user location but when I go for remote server database backup and restore I connect remote sqlserver and get backup then the backup file will be created on remote system not local system then I restore that database it will be restore from remote system back file if I remove that file from remote system then restore. Gives the exception.

Restore sqlRestore = new Restore();
               
BackupDeviceItem deviceItem = new BackupDeviceItem(dataFilePath + "\\" + databaseName + ".bak", DeviceType.File);
               
sqlRestore.Devices.Add(deviceItem);
sqlRestore.Database = databaseName;

ServerConnection connection = new ServerConnection(serverName);
connection.LoginSecure = false;
connection.Login = "gjgjg";
connection.Password = "ytryr";
Server sqlServer = new Server(connection);
                               
sqlRestore.Action = RestoreActionType.Database;
String dataFileLocation = dataFilePath + "\\" + databaseName + ".mdf";
String logFileLocation = dataFilePath + "\\" + databaseName + "_log.ldf";
               
//System.Data.DataTable logicalRestoreFiles = sqlRestore.ReadFileList(sqlServer);
//sqlRestore.RelocateFiles.Add(new RelocateFile(logicalRestoreFiles.Rows[0][0].ToString(),dataFileLocation)); 
//sqlRestore.RelocateFiles.Add(new RelocateFile(logicalRestoreFiles.Rows[1][0].ToString(),logFileLocation));
               
sqlRestore.ReplaceDatabase = false;
//sqlRestore.Complete += new ServerMessageEventHandler(sqlRestore_Complete);
sqlRestore.PercentCompleteNotification = 10;
//sqlRestore.PercentComplete += new PercentCompleteEventHandler(sqlRestore_PercentComplete);
sqlRestore.SqlRestore(sqlServer);


我想将.bak文件存储在本地系统上并从本地还原到远程服务器

谢谢


I want to store .bak file on local system and restore from local to remote server

Thank You

推荐答案

我也有同样的问题.有人可以帮忙吗?
I too have the same problem. Someone can help?


这篇关于备份和还原远程sqlserver的smo claase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆