数据库还原时总会提示,已将数据库上下文更改为master,还原数据库不就是借助master数据库的吗?
该怎么改就好了呢?代码如下:
//还原数据库
void CRestoreDlg::OnRestore() 
{
// TODO: Add your control notification handler code here
UpdateData(); //数据的更新
if(m_strPath=="")
{
MessageBox("请选择路径!");
return ;
}
_ConnectionPtr pConnection;
try
{
HRESULT hr=pConnection.CreateInstance("ADODB.Connection");//创建Connection对象
pConnection->Open("driver={SQL Server};Server=.;DATABASE=master;","","",adModeUnknown);
CString sql;//定义字符串变量
sql.Format("use master restore database hmsys from disk = '%s' with move 'hmsys_data' to 'c:\\hmsys.mdf', move 'hmsys_log' to 'c:\\hmsys.ldf'", m_strPath);
pConnection->Execute((_bstr_t)sql, NULL, adCmdText);
MessageBox("还原成功!");
pConnection->Close();//关闭连接
}
CATCH_ERROR;}数据库