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

2025-05-17 17:27:38
推荐回答(1个)
回答(1):

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)
{

}

}