为什么运行时总是出现“This application has requested the Runtime to terminate it in an usual way.Please contact the application'

cnsgp 2006-04-18 10:04:22
为什么运行时总是出现“This application has requested the Runtime to terminate it in an usual way.Please contact the application's support team for more information.”
我是VC菜鸟,在学习《Visual C++6.0应用编程150例》时,其中的部分数据库编程例子总是无法正常工作。其特征是:
1.都是控制台程序
2.编译运行时,都出现“This application has requested the Runtime to terminate it in an usual way.Please contact the application's support team for more information.”提示,调试时,出现“Unhandled Exception in Kernel32.dll...”,然后程序非正常退出。这样的程序例子有10个左右。恳请高手指点!
附:
源码1:修改数据库密码
// Example.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include "Example.h"
#include "afxdao.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// The one and only application object

CWinApp theApp;

using namespace std;

void SetDBPassword( LPCTSTR pDB, LPCTSTR pszOldPassword, LPCTSTR pszNewPassword )
{
CDaoDatabase db;
CString strConnect( _T( ";pwd=" ) );
db.Open(pDB,TRUE,FALSE,strConnect+pszOldPassword );
COleVariant NewPassword( pszNewPassword, VT_BSTRT ),
OldPassword( pszOldPassword, VT_BSTRT );
DAO_CHECK( db.m_pDAODatabase->NewPassword( V_BSTR( &OldPassword ),
V_BSTR( &NewPassword ) ) );
db.Close();
}

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;

// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
AfxGetModuleState()->m_dwVersion = 0x0601;
AfxDaoInit();

//LPCTSTR pDB=_T("D:\\Microsoft Visual Studio\\VB98\\NWIND.MDB");
LPCTSTR pDB=_T("C:\\Microsoft Visual Studio\\VB98\\NWIND.MDB");
LPCTSTR pszOldPassword=_T("");
LPCTSTR pszNewPassword=_T("hello");
SetDBPassword(pDB,pszOldPassword,pszNewPassword);
}

return nRetCode;
}



源码2:用DAO在数据库中执行SQL语句

// Example.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "Example.h"
#include "afxdao.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// The one and only application object

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;

// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
CDaoDatabase m_MyDatabase;
m_MyDatabase.Open("c:\\BIBLIO.MDB");
printf("Tables' Count: %d\n",m_MyDatabase.GetTableDefCount());
//LPCTSTR str_SQL="Create Table NewTable(Field1 Text(10),Field2 Short)";
CString str_SQL="Create Table NewTable(Field1 Text(10),Field2 Short)";
m_MyDatabase.Execute(str_SQL);
//LPCTSTR str_SQL="Create Table NewTable(Field1 Text(10),Field2 Short)";
//m_MyDatabase.Execute("Create Table NewTable",128);
m_MyDatabase.Close();
m_MyDatabase.Open("c:\\BIBLIO.MDB");
printf("Tables' Count: %d\n",m_MyDatabase.GetTableDefCount());
m_MyDatabase.Close();
}

return nRetCode;
}
...全文
36288 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
zyq5945 2010-06-18
  • 打赏
  • 举报
回复
结贴提醒

如果您的问题已经得到解决,请您早日结贴,如四日后未结贴,该贴将做强制结贴处理。
如果您的问题尚未得到解决,请回复方便其他网友知道你仍关注该问题。如四日后没有其他网友和楼主本人回复,该贴将做强制结贴处理。
如果贴子只有楼主和强制结贴的版主本人回复,将按无满意结帖处理。

注:强制结贴版主本人将不会分配答题分
surf515 2010-06-03
  • 打赏
  • 举报
回复
帮顶~~
  • 打赏
  • 举报
回复
貌似连接字字符串不对的时候也会出现这种问题。
今天我还遇到。
foryond 2010-05-31
  • 打赏
  • 举报
回复
http://zhidao.baidu.com/question/118363752.html
jasonshark 2006-05-29
  • 打赏
  • 举报
回复
ODBC数据源没配好吧?
sti01 2006-05-29
  • 打赏
  • 举报
回复
关注
Stefine 2006-04-18
  • 打赏
  • 举报
回复
可能是DAO连接DB还需要什么DLL吧

就像ADO一样,需要链接msado15.dll

你找找资料看,我也没用过DAO访问DB,

cnsgp 2006-04-18
  • 打赏
  • 举报
回复
谢谢littleeagle007(007),我试了,去掉using namespace std;后连编译都不能通过:
Compiling...
Example.cpp
E:\itbook\VC6应用编程150例\5数据库开发实例\127修改数据库密码\Example.cpp(41) : error C2065: 'cerr' : undeclared identifier
E:\itbook\VC6应用编程150例\5数据库开发实例\127修改数据库密码\Example.cpp(41) : error C2297: '<<' : illegal, right operand has type 'char [39]'
E:\itbook\VC6应用编程150例\5数据库开发实例\127修改数据库密码\Example.cpp(41) : error C2065: 'endl' : undeclared identifier
Error executing cl.exe.
Creating browse info file...

Example.exe - 3 error(s), 0 warning(s)
littleeagle007 2006-04-18
  • 打赏
  • 举报
回复
using namespace std; 你看去掉怎么样,我觉得好象有点别扭,你上面用了 .h 下面就不要在用std了

4,011

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧