CDataSave::ConStr()是我拼凑的数据库连接字符串,当这个字符串正确的时候程序一切正常.但是当这个字符串错误的时候,就会弹出错误:
Runtime Error!
Program: E:\wor...
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
代码中捕捉不到这个错误,无解中,特来请教.
代码如下:
_ConnectionPtr pMyConnect = NULL;
try
{
HRESULT hr1 = pMyConnect.CreateInstance("ADODB.Connection");///创建Connection对象
if(SUCCEEDED(hr1))//创建成功
{
HRESULT hr2=pMyConnect->Open(CDataSave::ConStr(),"","",adModeUnknown);///连接数据库
if(!SUCCEEDED(hr2)) return false;//连接失败
}
else
return false;
}
catch (_com_error e) //捕捉异常
{
CString strComError;
strComError.Format("Error: .lx\nError Message: %s\nSource: %s\nDescription: %s",
e.Error(),e.ErrorMessage(),(LPCSTR) e.Source(),(LPCSTR) e.Description());
MessageBox(NULL,strComError,"Database Error",MB_ICONEXCLAMATION);
return false;
}
return true;
Runtime Error!
Program: E:\wor...
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
代码中捕捉不到这个错误,无解中,特来请教.
代码如下:
_ConnectionPtr pMyConnect = NULL;
try
{
HRESULT hr1 = pMyConnect.CreateInstance("ADODB.Connection");///创建Connection对象
if(SUCCEEDED(hr1))//创建成功
{
HRESULT hr2=pMyConnect->Open(CDataSave::ConStr(),"","",adModeUnknown);///连接数据库
if(!SUCCEEDED(hr2)) return false;//连接失败
}
else
return false;
}
catch (_com_error e) //捕捉异常
{
CString strComError;
strComError.Format("Error: .lx\nError Message: %s\nSource: %s\nDescription: %s",
e.Error(),e.ErrorMessage(),(LPCSTR) e.Source(),(LPCSTR) e.Description());
MessageBox(NULL,strComError,"Database Error",MB_ICONEXCLAMATION);
return false;
}
return true;
解决方案 »
- 动态卸载DLL时内存泄漏
- 一个不太简单的问题,高手留步~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
- 请问“WCHAR Name[0];”这个说明语句应改造成什么?
- 256色BMP转PCX错位的问题
- 如何将sql数据库中查询结果写成excel文件?
- 关于字体间距的一个小问题,回答马上给分.
- 奇怪了。单步跟踪调试能输出预期结果,但编译好了以后运行结果不一样了。
- --------------我想在一个位图背景上画一些封闭曲线,比如说一个圆,且不能将背景遮盖--------up者有分
- 请问在VC中使用ADO连接Oracle数据库,如何判断连接断开
- 谁能给俺详细讲讲ReleaseMinSize和ReleaseMinDependency版本的差异,谢了先!
- VC++的以太网编程接口
- dx9.0中的纹理透明处理
举例来说
CDataSave::ConStr()若是正确的值比如"driver={SQL Server};Server=192.168.1.40;DATABASE=ManageAdmin;UID=sa;PWD="
时,不会出现任何错误;
但是这个值若是错误的,比如:"driver={SQL Server};Server=;DATABASE=;UID=;PWD="
就会出来
Runtime Error!
Program: E:\wor...
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
错误.迷茫~!!!
也可以试试用
__try{
...
}
__except(...){
...
}
看能否捕获..
改用_RecordsetPtr不用_ConnectionPtr
然后连接
try..catch
就好了开心