_ConnectionPtr m_pConnection
版本1:
m_pConnection->Open("Data Source=adotest;UID=sa;PWD=;","","",adModeUnknown);
版本2:
m_pConnection->Open("driver={SQL
Server};Server=127.0.0.1;DATABASE=vckbase;UID=sa;PWD=139","","",adModeUnknown);
版本3:
m_pConnection->Open("Data Source=adotest;","","",adModeUnknown);
VC连接 myslq数据库
try
{ CoInitialize(NULL);
hr = m_pConnection.CreateInstance("ADODB.Connection");
if (SUCCEEDED(hr))
{
char connectStr[500];
sprintf(connectStr,"Driver=MySQL ODBC 5.1 Driver;DATABASE=phoneRegisterManage;server=%s","192.168.1.203");
_bstr_t strConnect=connectStr;
hr = m_pConnection->Open(strConnect,"admin","something",adModeUnknown);
}
AfxMessageBox("数据库连接成功");
}
VC连接 Access数据库
// 打开本地Access库 m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=menu.mdb","","",adModeUnknown);