连接远程数据库 SQLSERVER2005
CString strConn = _T("driver={SQL Server};Server=192.168.57.49,1433;DATABASE=数据名;UID=用户名;PWD=密码");
CString strConn =
(Driver={SQL Native Client}是连接本地数据库字符串,连接远程数据库会出错)
连接本地数据库
SQLSERVER2005
CString strConnServer2005 = _T("Provider=SQLOLEDB.1;Persist Security Info=False;Initial Catalog=DATABASENAME;Data Source=127.0.0.1");
SQLSERVER2008
CString strConnServer2008 = _T("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DATABASENAME;Data Source=.\\SQLEXPRESS;User ID=用户名;Password=密码;");
测试通过(.\\SQLEXPRESS 转义\看情况,因为这里是放在字符串中所以需要 )
m_pConnection->Open(_bstr_t(strConn),_bstr_t(strUserId),_bstr_t(strPassword),adModeUnknown);
连接本地数据库
SQLSERVER2005
CString strConnServer2005 = _T("Provider=SQLOLEDB.1;Persist Security Info=False;Initial Catalog=DATABASENAME;Data Source=127.0.0.1");
SQLSERVER2008
CString strConnServer2008 = _T("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DATABASENAME;Data Source=.\\SQLEXPRESS;User ID=用户名;Password=密码;");
测试通过(.\\SQLEXPRESS 转义\看情况,因为这里是放在字符串中所以需要 )