ErrorInfo CfinishschoolSApp::BakDB2(CString dbsource, CString uname, CString pwd, CString bakname, CString bakpath)
{
ErrorInfo error;
try{
_bstr_t bstrConn;
CString strMdbConn;
strMdbConn.Format("Provider='SQLOLEDB.1';User ID=%s;Password=%s;Persist Security Info=False;"
"initial catalog=%s;server=%s",
uname, pwd, dbsource, "192.168.1.105");
bstrConn = strMdbConn;
CString sqlstr ;
sqlstr.Format("BACKUP DATABASE FinishSchoolDB TO DISK = '%s%s'", bakpath, bakname);
::CoInitialize(NULL); //初始化Com
_ConnectionPtr connObject = NULL;
_CommandPtr commandObject = NULL;
_RecordsetPtr recordSetObject = NULL;
TESTHR(connObject.CreateInstance(__uuidof(Connection)));
TESTHR(commandObject.CreateInstance(__uuidof(Command)));
TESTHR(recordSetObject.CreateInstance(__uuidof(Recordset)));
connObject->Open(bstrConn, "", "", adConnectUnspecified);
commandObject->ActiveConnection = connObject;
commandObject->CommandText = _bstr_t(sqlstr);
commandObject->CommandType = adCmdText;
commandObject->Prepared = true;
commandObject->Execute(NULL, NULL, adCmdText);
}
catch(_com_error* e)
{
CString tipinfo = e->Description();
theApp.LogTrace2(tipinfo.GetBuffer(0));
}
CoUninitialize();
return error;
}
备份远程数据库Code
猜你喜欢
转载自blog.csdn.net/nishuodeqianshou/article/details/53281972
今日推荐
周排行