yu_Vc:我的代码如下:void CCEgsView::OnInitialUpdate()
{
CListView::OnInitialUpdate();
if (!AfxOleInit())
{
AfxMessageBox("ole 初始化错误");
}
HRESULT hr;
_bstr_t source("Driver=SQL Server;Server=AHMTFWQ;Uid=sa;Pwd=;database=gsxd");
_bstr_t user("yxz");
_bstr_t pwd("");
try{hr=m_connection.CreateInstance(__uuidof(Connection));
if(SUCCEEDED(hr))
hr=m_connection->Open(source,user,pwd,16);
if(SUCCEEDED(hr))
hr=m_recordset.CreateInstance(__uuidof(Recordset));
if(SUCCEEDED(hr))
m_fConnected=TRUE;
else
m_fConnected=FALSE;
}
catch(_com_error *e){
MessageBox(e->ErrorMessage());
m_fConnected=FALSE;
}
if(!m_fConnected)
MessageBox("ADO数据源初始化失败!");
else
m_strSource=(const char *)source;
// TODO: You may populate your ListView with items by directly accessing
// its list control through a call to GetListCtrl().
}
为什么在RecordSet的open(......)是连接不上????????
{
CListView::OnInitialUpdate();
if (!AfxOleInit())
{
AfxMessageBox("ole 初始化错误");
}
HRESULT hr;
_bstr_t source("Driver=SQL Server;Server=AHMTFWQ;Uid=sa;Pwd=;database=gsxd");
_bstr_t user("yxz");
_bstr_t pwd("");
try{hr=m_connection.CreateInstance(__uuidof(Connection));
if(SUCCEEDED(hr))
hr=m_connection->Open(source,user,pwd,16);
if(SUCCEEDED(hr))
hr=m_recordset.CreateInstance(__uuidof(Recordset));
if(SUCCEEDED(hr))
m_fConnected=TRUE;
else
m_fConnected=FALSE;
}
catch(_com_error *e){
MessageBox(e->ErrorMessage());
m_fConnected=FALSE;
}
if(!m_fConnected)
MessageBox("ADO数据源初始化失败!");
else
m_strSource=(const char *)source;
// TODO: You may populate your ListView with items by directly accessing
// its list control through a call to GetListCtrl().
}
为什么在RecordSet的open(......)是连接不上????????
hr=m_connection->Open(source,user,pwd,-1);
我是这样连的:
m_pCon.CreateInstance(__uuidof(Connection)); //创建实例
m_pSet.CreateInstance(__uuidof(Recordset));
dns=dns="driver={SQL Server};server=MP;uid=sa;pwd=;database=test";
try
{
hr=m_pCon->Open((_bstr_t)dns,"","",adConnectUnspecified);
}
catch(...)
{
MessageBox("连接数据库出错","提示信息",MB_OK|MB_ICONERROR);
PostMessage(WM_CLOSE);
return ;
}