64,687
社区成员
发帖
与我相关
我的任务
分享
void CTestdbDlg::OnButton2()
{
// TODO: Add your control notification handler code here
// TODO: Add your control notification handler code here
_ConnectionPtr m_pConnection;
m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象
m_pConnection->ConnectionTimeout = 8;
TRACE("%s\n",m_sConn);
try{
hr = m_pConnection->Open("Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=master;Data Source=Server","","",adModeUnknown);
if (FAILED(hr))
{
AfxMessageBox("不能连接数据库!");
return ;
}
else
AfxMessageBox("连接数据库成功!");
}
catch(_com_error e)
{
AfxMessageBox("不能打开数据库!");
return ;
}
}