ADO连Sql server 未知错误?(连不上)
stdAfx.h中加了
#import "D:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename ("EOF","adoEOF")
xxdlg.cpp中OnInitDialog()加入
::CoInitialize(NULL);
HRESULT hr;
try
{
hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象
if(SUCCEEDED(hr))
{
m_pConnection->Open("driver={SQLServer};Server=XIUYU;DATABASE=nc;UID=sa;PWD=gongyuan","","",adModeUnknown);
}
}
catch(_com_error e)///捕捉异常
{
CString errormessage; errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage()); AfxMessageBox(errormessage);///显示错误信息
}
运行后出现"连接数据库失败!错误信息:未指定的错误"
这是什么问题啊,怎么解决啊?