using namespace ADODB;
我不加using namespace ADODB这句就无法通过编译,老提示未找到标识符当声明一个别ADO对象时,如_RecordsetPtr pPtr;.(我不知道是不是这里的关闭)
在initdialog里加入了:
CDialog::OnInitDialog();
::CoInitialize(NULL); //初始化OLE/COM库环境
接着:
一个按钮事件里:
CString strSRC,strSQL;
strSRC="Driver=SQL Server;server=192.168.0.100;database=user;uid=sa;pwd=1983131";
strSQL="select * from USER";
_variant_t varSQL(strSQL);
_variant_t varSrc(strSRC);
_RecordsetPtr pPtr;
if (FAILED(pPtr.CreateInstance("ADODB.Recordset")))
{
AfxMessageBox("Create Recordset Instance failed!");
return;
}
if(FAILED(pPtr->Open(varSQL,varSrc,adOpenDynamic,adLockOptimistic,adCmdText)))
{
AfxMessageBox("Open table failed!");
pPtr.Release();
return;
}
if(!pPtr->ADOEOF)
{
EndDialog(1);
control dlg;
dlg.DoModal();
}else MessageBox("用户名或密码有误,请重新输入","提示",MB_ICONINFORMATION);
虽然通过编译了,但当我点击"确定"按钮后,我快疯了.
xxx.exe中的0x7c815dea处未处理的异常.microsoft c++ exception:_com_error @ 0x0012f144
哪位大哥路过能帮帮小弟吗?感激不尽,跪谢!
13 个解决方案
#1
调试,具体哪行出错。
#2
ADODB::_RecordsetPtr pPtr;
#3
没看到你openconnection呀?
_ConnectionPtr pConnect;
pConnect.CreateInstance(_uuidof(Connection));
pConnect->Open(varSrc);
_ConnectionPtr pConnect;
pConnect.CreateInstance(_uuidof(Connection));
pConnect->Open(varSrc);
#4
这一句有问题:
pPtr->Open(varSQL,varSrc,adOpenDynamic,adLockOptimistic,adCmdText)
到这儿就xxx.exe中的0x7c815dea处未处理的异常.microsoft c++ exception:_com_error @ 0x0012f144
pPtr->Open(varSQL,varSrc,adOpenDynamic,adLockOptimistic,adCmdText)
到这儿就xxx.exe中的0x7c815dea处未处理的异常.microsoft c++ exception:_com_error @ 0x0012f144
#5
你try catch(_com_error & e){ e.ErrorMessage();}看看错误是什么?
#6
疯了,还是这个提示xxx.exe中的0x7c815dea处未处理的异常.microsoft c++ exception:_com_error @ 0x0012f144.和以前一样.
#7
msado15.tli同时也打开了,向下面这样显示.
inline HRESULT Recordset15::Open ( const _variant_t & Source, const _variant_t & ActiveConnection, enum CursorTypeEnum CursorType, enum LockTypeEnum LockType, long Options ) {
HRESULT _hr = raw_Open(Source, ActiveConnection, CursorType, LockType, Options);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
-> return _hr;
}
inline HRESULT Recordset15::Open ( const _variant_t & Source, const _variant_t & ActiveConnection, enum CursorTypeEnum CursorType, enum LockTypeEnum LockType, long Options ) {
HRESULT _hr = raw_Open(Source, ActiveConnection, CursorType, LockType, Options);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
-> return _hr;
}
#8
是不是connectstring 不对?
用oledb的connectstring方式如下:
"Provider=SQLOLEDB;Data Source=serverName;"
Initial Catalog=databaseName;
User ID=MyUserID;Password=MyPassword;"
用oledb的connectstring方式如下:
"Provider=SQLOLEDB;Data Source=serverName;"
Initial Catalog=databaseName;
User ID=MyUserID;Password=MyPassword;"
#9
你用try catch没捕获到异常么?
#10
是的,没有捕获到任何异常,仍然提示:xxx.exe中的0x7c815dea处未处理的异常.microsoft c++ exception:_com_error @ 0x0012f144.和以前一样.
中止 或者 继续.
中止 或者 继续.
#11
求求各位了有什么好的建议吗?我急死了.
#12
看看pPtr指针指的地址,不会是空指针吧。
#13
BOOL CDlgRecordset::QueryRecord()
{
_CommandPtr cmd;
_RecordsetPtr rs;
_ConnectionPtr conn;
_variant_t vra;
VARIANT *vt1 = NULL;
try
{
/* cmd.CreateInstance( __uuidof(Command));
rs.CreateInstance(__uuidof(Recordset));
conn.CreateInstance(__uuidof(Connection));*/
UpdateData(TRUE);
theApp.m_pConnection->PutCursorLocation(adUseClient);
/* conn->CursorLocation = adUseClient;
conn->Open(_bstr_t( theApp.m_pConnection.GetInterfacePtr() ), L"", L"", -1);
cmd->ActiveConnection = conn;
cmd->CommandText = (_bstr_t) m_strQuery;
cmd->CommandType = adCmdText;
rs = cmd->Execute(&vra,vt1, adCmdText);*/
/*rs->PutRefActiveConnection(theApp.m_pConnection);
rs->Open((_bstr_t)m_strQuery,
theApp.m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);*/
/// ((CTestDllApp*)(&theApp))->m_pConnection
/// m_pRecordset.CreateInstance(__uuidof(Recordset));
/* m_pRecordset->Open((_bstr_t)m_strQuery,
_variant_t((IDispatch*)theApp.m_pConnection, TRUE),
adOpenStatic,
adLockOptimistic,
adCmdText);*/
if(m_pRecordset->State==1)
{
m_pRecordset->Close();
}
m_pRecordset->Open((_bstr_t)m_strQuery,
theApp.m_pConnection.GetInterfacePtr(),//»ñÈ¡¿â½Ó¿âµÄIDispatchÖ¸Õë
adOpenStatic,
adLockOptimistic,
adCmdText);
/* m_DataGrid.SetRefDataSource(NULL);
m_DataGrid.SetRefDataSource((LPUNKNOWN)m_pRecordset);
m_DataGrid.Refresh();*/
}
catch (_com_error &e)
{
::MessageBox(NULL,e.Description(),"Ìáʾ",MB_OK);
}
m_DataGrid.SetRefDataSource((LPUNKNOWN)m_pRecordset);
m_DataGrid.Refresh();
UpdateData(FALSE);
//m_pRecordset->Close();
return true;
}
{
_CommandPtr cmd;
_RecordsetPtr rs;
_ConnectionPtr conn;
_variant_t vra;
VARIANT *vt1 = NULL;
try
{
/* cmd.CreateInstance( __uuidof(Command));
rs.CreateInstance(__uuidof(Recordset));
conn.CreateInstance(__uuidof(Connection));*/
UpdateData(TRUE);
theApp.m_pConnection->PutCursorLocation(adUseClient);
/* conn->CursorLocation = adUseClient;
conn->Open(_bstr_t( theApp.m_pConnection.GetInterfacePtr() ), L"", L"", -1);
cmd->ActiveConnection = conn;
cmd->CommandText = (_bstr_t) m_strQuery;
cmd->CommandType = adCmdText;
rs = cmd->Execute(&vra,vt1, adCmdText);*/
/*rs->PutRefActiveConnection(theApp.m_pConnection);
rs->Open((_bstr_t)m_strQuery,
theApp.m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);*/
/// ((CTestDllApp*)(&theApp))->m_pConnection
/// m_pRecordset.CreateInstance(__uuidof(Recordset));
/* m_pRecordset->Open((_bstr_t)m_strQuery,
_variant_t((IDispatch*)theApp.m_pConnection, TRUE),
adOpenStatic,
adLockOptimistic,
adCmdText);*/
if(m_pRecordset->State==1)
{
m_pRecordset->Close();
}
m_pRecordset->Open((_bstr_t)m_strQuery,
theApp.m_pConnection.GetInterfacePtr(),//»ñÈ¡¿â½Ó¿âµÄIDispatchÖ¸Õë
adOpenStatic,
adLockOptimistic,
adCmdText);
/* m_DataGrid.SetRefDataSource(NULL);
m_DataGrid.SetRefDataSource((LPUNKNOWN)m_pRecordset);
m_DataGrid.Refresh();*/
}
catch (_com_error &e)
{
::MessageBox(NULL,e.Description(),"Ìáʾ",MB_OK);
}
m_DataGrid.SetRefDataSource((LPUNKNOWN)m_pRecordset);
m_DataGrid.Refresh();
UpdateData(FALSE);
//m_pRecordset->Close();
return true;
}
#1
调试,具体哪行出错。
#2
ADODB::_RecordsetPtr pPtr;
#3
没看到你openconnection呀?
_ConnectionPtr pConnect;
pConnect.CreateInstance(_uuidof(Connection));
pConnect->Open(varSrc);
_ConnectionPtr pConnect;
pConnect.CreateInstance(_uuidof(Connection));
pConnect->Open(varSrc);
#4
这一句有问题:
pPtr->Open(varSQL,varSrc,adOpenDynamic,adLockOptimistic,adCmdText)
到这儿就xxx.exe中的0x7c815dea处未处理的异常.microsoft c++ exception:_com_error @ 0x0012f144
pPtr->Open(varSQL,varSrc,adOpenDynamic,adLockOptimistic,adCmdText)
到这儿就xxx.exe中的0x7c815dea处未处理的异常.microsoft c++ exception:_com_error @ 0x0012f144
#5
你try catch(_com_error & e){ e.ErrorMessage();}看看错误是什么?
#6
疯了,还是这个提示xxx.exe中的0x7c815dea处未处理的异常.microsoft c++ exception:_com_error @ 0x0012f144.和以前一样.
#7
msado15.tli同时也打开了,向下面这样显示.
inline HRESULT Recordset15::Open ( const _variant_t & Source, const _variant_t & ActiveConnection, enum CursorTypeEnum CursorType, enum LockTypeEnum LockType, long Options ) {
HRESULT _hr = raw_Open(Source, ActiveConnection, CursorType, LockType, Options);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
-> return _hr;
}
inline HRESULT Recordset15::Open ( const _variant_t & Source, const _variant_t & ActiveConnection, enum CursorTypeEnum CursorType, enum LockTypeEnum LockType, long Options ) {
HRESULT _hr = raw_Open(Source, ActiveConnection, CursorType, LockType, Options);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
-> return _hr;
}
#8
是不是connectstring 不对?
用oledb的connectstring方式如下:
"Provider=SQLOLEDB;Data Source=serverName;"
Initial Catalog=databaseName;
User ID=MyUserID;Password=MyPassword;"
用oledb的connectstring方式如下:
"Provider=SQLOLEDB;Data Source=serverName;"
Initial Catalog=databaseName;
User ID=MyUserID;Password=MyPassword;"
#9
你用try catch没捕获到异常么?
#10
是的,没有捕获到任何异常,仍然提示:xxx.exe中的0x7c815dea处未处理的异常.microsoft c++ exception:_com_error @ 0x0012f144.和以前一样.
中止 或者 继续.
中止 或者 继续.
#11
求求各位了有什么好的建议吗?我急死了.
#12
看看pPtr指针指的地址,不会是空指针吧。
#13
BOOL CDlgRecordset::QueryRecord()
{
_CommandPtr cmd;
_RecordsetPtr rs;
_ConnectionPtr conn;
_variant_t vra;
VARIANT *vt1 = NULL;
try
{
/* cmd.CreateInstance( __uuidof(Command));
rs.CreateInstance(__uuidof(Recordset));
conn.CreateInstance(__uuidof(Connection));*/
UpdateData(TRUE);
theApp.m_pConnection->PutCursorLocation(adUseClient);
/* conn->CursorLocation = adUseClient;
conn->Open(_bstr_t( theApp.m_pConnection.GetInterfacePtr() ), L"", L"", -1);
cmd->ActiveConnection = conn;
cmd->CommandText = (_bstr_t) m_strQuery;
cmd->CommandType = adCmdText;
rs = cmd->Execute(&vra,vt1, adCmdText);*/
/*rs->PutRefActiveConnection(theApp.m_pConnection);
rs->Open((_bstr_t)m_strQuery,
theApp.m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);*/
/// ((CTestDllApp*)(&theApp))->m_pConnection
/// m_pRecordset.CreateInstance(__uuidof(Recordset));
/* m_pRecordset->Open((_bstr_t)m_strQuery,
_variant_t((IDispatch*)theApp.m_pConnection, TRUE),
adOpenStatic,
adLockOptimistic,
adCmdText);*/
if(m_pRecordset->State==1)
{
m_pRecordset->Close();
}
m_pRecordset->Open((_bstr_t)m_strQuery,
theApp.m_pConnection.GetInterfacePtr(),//»ñÈ¡¿â½Ó¿âµÄIDispatchÖ¸Õë
adOpenStatic,
adLockOptimistic,
adCmdText);
/* m_DataGrid.SetRefDataSource(NULL);
m_DataGrid.SetRefDataSource((LPUNKNOWN)m_pRecordset);
m_DataGrid.Refresh();*/
}
catch (_com_error &e)
{
::MessageBox(NULL,e.Description(),"Ìáʾ",MB_OK);
}
m_DataGrid.SetRefDataSource((LPUNKNOWN)m_pRecordset);
m_DataGrid.Refresh();
UpdateData(FALSE);
//m_pRecordset->Close();
return true;
}
{
_CommandPtr cmd;
_RecordsetPtr rs;
_ConnectionPtr conn;
_variant_t vra;
VARIANT *vt1 = NULL;
try
{
/* cmd.CreateInstance( __uuidof(Command));
rs.CreateInstance(__uuidof(Recordset));
conn.CreateInstance(__uuidof(Connection));*/
UpdateData(TRUE);
theApp.m_pConnection->PutCursorLocation(adUseClient);
/* conn->CursorLocation = adUseClient;
conn->Open(_bstr_t( theApp.m_pConnection.GetInterfacePtr() ), L"", L"", -1);
cmd->ActiveConnection = conn;
cmd->CommandText = (_bstr_t) m_strQuery;
cmd->CommandType = adCmdText;
rs = cmd->Execute(&vra,vt1, adCmdText);*/
/*rs->PutRefActiveConnection(theApp.m_pConnection);
rs->Open((_bstr_t)m_strQuery,
theApp.m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);*/
/// ((CTestDllApp*)(&theApp))->m_pConnection
/// m_pRecordset.CreateInstance(__uuidof(Recordset));
/* m_pRecordset->Open((_bstr_t)m_strQuery,
_variant_t((IDispatch*)theApp.m_pConnection, TRUE),
adOpenStatic,
adLockOptimistic,
adCmdText);*/
if(m_pRecordset->State==1)
{
m_pRecordset->Close();
}
m_pRecordset->Open((_bstr_t)m_strQuery,
theApp.m_pConnection.GetInterfacePtr(),//»ñÈ¡¿â½Ó¿âµÄIDispatchÖ¸Õë
adOpenStatic,
adLockOptimistic,
adCmdText);
/* m_DataGrid.SetRefDataSource(NULL);
m_DataGrid.SetRefDataSource((LPUNKNOWN)m_pRecordset);
m_DataGrid.Refresh();*/
}
catch (_com_error &e)
{
::MessageBox(NULL,e.Description(),"Ìáʾ",MB_OK);
}
m_DataGrid.SetRefDataSource((LPUNKNOWN)m_pRecordset);
m_DataGrid.Refresh();
UpdateData(FALSE);
//m_pRecordset->Close();
return true;
}