出现“未指定的错误”
::CoInitialize(NULL);
try
{
// 创建Connection对象
_ConnectionPtr m_pConnection(__uuidof(Connection));
// 设置连接字符串,必须是BSTR型或者_bstr_t类型
_bstr_t strConnect = "Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=UserMan;Data Source=localhost;";
m_pConnection->Open(strConnect,"","",adModeUnknown);
// 判断连接状态是否为连接
if(m_pConnection->State == adStateOpen)
MessageBox("连接数据库");
// 关闭连接
m_pConnection->Close();
// 判断连接状态是否为关闭
if(m_pConnection->State == adStateClosed)
MessageBox("断开连接");
}
// 捕捉异常
catch(_com_error e)
{
// 显示错误信息
AfxMessageBox(e.ErrorMessage());
}
请大侠帮帮忙