ADO链接SQLSERVER
安装最好是用混合登陆安装,不然要改
在安全性->登录名->右键sa->属性->状态
1 建立数据源
在Manage中看到名称填一下就好,数据源名称随便写。
2 随手建一个文本文档,改成udl后缀,打开,输入内容连上后关闭
3 再用记事本打开刚刚的文件即可得到字符串,记得加上ID=sa;Password=***;
4
::CoInitialize(NULL);
HRESULT t_hr = m_ptrConnection.CreateInstance(__uuidof(Connection));
_bstr_t strConnect = "Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;Password=***;Data Source=SQLSERVER;Initial Catalog=***";
m_ptrConnection->CursorLocation = adUseClient;
m_ptrConnection->IsolationLevel = adXactReadCommitted;
try
{
m_ptrConnection->Open(strConnect, "", "", adModeUnknown);
return TRUE;
}
catch (_com_error e)
{
printf("%s",(char *)e.Description());
return FALSE;
}