vc++通过ADO连接数据库连接字符串的问题!!!!

_ConnectionPtr pCon(__uuidof(Connection));
pCon->ConnectionString="MSSQLSERVER;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Student"; 请问此链接字符串应该如何书写,我用的本地数据库windows 身份验证模式 数据库服务器名字是RW6YXGLAY8R6JMB 数据库名称是student ,望高手指点

void CTestDlg::OnButton1()
{
// TODO: Add your control notification handler code here
try{ HRESULT hr;
CString sql;
sql="Provider=SQLOLEDB.1;Password=;Persist Security Info=True;User ID=sa;Initial Catalog=student ;Data Source=192.168.2.134";//你是SQL的话最好写IP,不要写服务器名
hr = this->m_pConnection.CreateInstance("ADODB.Connection");
if(SUCCEEDED(hr))
{
hr = this->m_pConnection->Open( (_bstr_t)sql,"","",adModeUnknown);
}

}catch(_com_error e)
{

}

}追问

嗯 谢谢,当执行到这一句的时候hr = this->m_pConnection->Open( (_bstr_t)sql,"","",adModeUnknown);

出现了如下错误提示

这是为什么呢 ?

追答

你是不是没有初始化com组件

追问

可以加你q吗?我发现字输入多了,百度知道不能提交提问。

追答

972252951,先给我采纳了,我刷点分

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答
大家正在搜