为什么运行时总是出现“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;
}