我正在使用此命令使用C#
恢复数据库private void btn_restore_Click(object sender, EventArgs e)
{
intializeConnections();
intializeDataServer();
if ((txt_bakfile.Text.ToString()!="") &&(txt_bakfile.Text !="System.Data.DataRow"))
{
Thread oThread = new Thread(new ThreadStart(frmWaitShow));
// clsLogs.LogEvent(4, "Tread is call");
oThread.Start();
// Create a new database restore operation
Restore rstDatabase = new Restore();
// Set the restore type to a database restore
rstDatabase.Action = RestoreActionType.Database;
// Set the database that we want to perform the restore on
rstDatabase.Database = DatabaseName;
// Set the backup device from which we want to restore, to a file
BackupDeviceItem bkpDevice = new BackupDeviceItem(txt_bakfile.Text.ToString(), DeviceType.File);
// Add the backup device to the restore type
rstDatabase.Devices.Add(bkpDevice);
// If the database already exists, replace it
rstDatabase.ReplaceDatabase = true;
// Perform the restore
rstDatabase.SqlRestore(srvSql);
oThread.Abort();
}
}
功能是:
public void intializeConnections()
{
string connString = SqlHelper.ConString;
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connString);
serverName = builder.DataSource;
DatabaseName = builder.InitialCatalog;
UserId = builder.UserID;
pw = builder.Password;
}
private void intializeDataServer()
{
// Create a new connection to the selected server name
ServerConnection srvConn = new ServerConnection(serverName);
// Log in using SQL authentication instead of Windows authentication
srvConn.LoginSecure = false;
// Give the login username
srvConn.Login = UserId;
// Give the login password
srvConn.Password = pw;
// Create a new SQL Server object using the connection we created
srvSql = new Server(srvConn);
}
这适用于我所有大小小于10MB的数据库,但是当我尝试恢复一个大小超过10MB的数据库时,它显示错误
服务器恢复失败' VARUN-PC'