Ado连接SQL Server2005

Ado连接SQL Server2005

::CoInitialize(NULL);

HRESULT hr = m_pConn.CreateInstance("ADODB.Connection");   //创建Connection对象
 if(!SUCCEEDED(hr))
    return;

_bstr_t  strConnect = "Provider=SQLNCLI;Data Source=服务器;Initial Catalog=数据库名;User Id=sa;Password=密码;";
(例如:_bstr_t  strConnect = "Provider=SQLNCLI;Data Source=127.0.0.1;Initial Catalog=TestDB;User Id=sa;Password=000000;";)

hr = m_pConn->Open(strConnect.c_str(), "", "", -1);
(_ConnectionPtr  m_pConn)


O了!

你可能感兴趣的:(Ado连接SQL Server2005)