VS2010编写的程序在Windows2003下访问sqlserver2005数据库
程序如下,在win7和XP下可正常运行,但在windows server 2003上运行显示
未处理异常:0xC0000005:读取位置0x00000004发生访问冲突,
请各位高手多多指点,小弟在此多谢!
m_pConnection=NULL;
//HRESULT hr=m_pConnection.CreateInstance(__uuidof(Connection));
HRESULT hr=m_pConnection.CreateInstance("ADODB.Connection");
if(FAILED(hr))
{
AfxMessageBox("m_pConnection没有建立",MB_OK);
return FALSE;
}
try
{
CString s;
m_pConnection-> ConnectionTimeout = 8;
//s.Format("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=%s;Data Source=%s", m_dbDataName, m_dbDataSource);
s.Format("Provider=SQLOLEDB; Server=%s;Database=%s; uid=%s; pwd=%s;", m_dbDataSource,m_dbDataName,m_dbUserName,m_dbPassWord);
bstr_t strConnect = s;
m_pConnection->Open(strConnect,"","",adModeUnknown);
return TRUE;
}
catch(_com_error &e)//(CException* ex)
{
//char buf[1024];
//ex->GetErrorMessage(buf, sizeof(buf));
CString s;
s.Format("连接不到数据库! %s", (char *)e.Description());
//ex->Delete();
AfxMessageBox(s);
return FALSE;
}
[解决办法]
用ADO助手测试看看是否能正常运行。