4,011
社区成员
发帖
与我相关
我的任务
分享
HRESULT hr = m_ptrConnection.CreateInstance("ADODB.Connection");
if (FAILED(hr))
{
if (!FAILED(::CoInitialize(NULL)))
{
m_ptrConnection.CreateInstance("ADODB.Connection");
}
}
CString strConnect;
strConnect.Format(_T(" Provider=SQLOLEDB.1; \
Persist Security Info=True; \
Data Source=%s; \
Initial Catalog=%s; \
User Id=%s; \
Password=%s; "),
strServerName,
strDatabaseName,
strLoginName,
strPassword);
ADODB::_CommandPtr a;
// 一下三句均崩溃
// m_ptrConnection->ConnectionTimeout = (long)5;
// m_ptrConnection->ConnectionTimeout = 5;
// m_ptrConnection->put_CommandTimeout(1L);
try
{
hr = m_ptrConnection->Open(_bstr_t(strConnect), "", "", 0);
}
catch (_com_error e)
{
return -1;
}
if (FAILED(hr))
{
return -1;
}