vc++ 连接数据库出错

[复制链接]
查看11 | 回复1 | 2009-8-2 18:31:22 | 显示全部楼层 |阅读模式
程序如下;
每次运行都显示:未指定的错误
这到底是连接不到数据库那还是代码里面缺少什么,我可是按照书上的写的
::CoInitialize(NULL);
AfxOleInit();
try
{
m_pConnection.CreateInstance("ADODB.Connection");
_bstr_t strConnect = "Provider=SQLOLEDB.1;Password=name;Persist Security Info=True;UserID=sa;Initial Catalog=pubs;Data Source=localhost;";
m_pConnection->Open(strConnect,"","",adModeUnknown);
if(m_pConnection->State==adStateOpen)
MessageBox(_T("连接数据库"));
else
MessageBox(_T("失败"));
m_pConnection->Close();
if(m_pConnection->State==adStateClosed)
MessageBox(_T("断开连接"));
}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage());
}

::CoUninitialize();

回复

使用道具 举报

千问 | 2009-8-2 18:31:22 | 显示全部楼层
给你看看我的我没用过SQLOLEDB
所以我也不知道你问题出哪CString strSRC;//数据库地址 strSRC="Driver=SQL Server;Server="; strSRC+=this->DBDlg.GetDBAddr(); strSRC+=";Database="; strSRC+=this->DBDlg.GetDBName(); strSRC+=";UID="; strSRC+=this->DBDlg.GetUserName(); strSRC+=";PWD="; strSRC+=this->DBDlg.GetPassword(); _variant_t varSRC(str...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行