高手快进:Runtime Error!

phoenixsoft 2003-08-20 03:05:51
我想做一个基于单文档的数据库(SQL Server)程序,通过选择菜单弹出一个对话框,输入相应的数据后单击OK按钮保存。但是在我单击OK按钮后,弹出两个错误对话框,内容分别如下:
1、Runtime Error!
program: F:\DB1.exe
abnormal program termination
2、
"0x6681250e" 指令引用的"0x0586f00f"内存。该内存不能为"written"。
要终止程序,请单击"确定"。
然后程序自动退出。

该如何解决?
还有。我对如何调试程序一窍不通,有没有人传授一下经验,或推荐一些教程之类的,不胜感激。
...全文
195 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
phoenixsoft 2003-08-31
  • 打赏
  • 举报
回复
up!!!
phoenixsoft 2003-08-21
  • 打赏
  • 举报
回复
DB1.h
////////////////////////////////////

#if !defined(AFX_DB1_H__ADCF8416_55EA_4533_A352_5688D57F0D60__INCLUDED_)
#define AFX_DB1_H__ADCF8416_55EA_4533_A352_5688D57F0D60__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif

#include "resource.h" // main symbols

/////////////////////////////////////////////////////////////////////////////
// CDB1App:
// See DB1.cpp for the implementation of this class
//

class CDB1App : public CWinApp
{
public:
bool ADOExecute(_RecordsetPtr &ADO,_variant_t &strSQL);
_RecordsetPtr m_pADORecord;
CString m_strCurrentUser;
CDB1App();

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDB1App)
public:
virtual BOOL InitInstance();
virtual int ExitInstance();
//}}AFX_VIRTUAL

// Implementation
//{{AFX_MSG(CDB1App)
afx_msg void OnAppAbout();
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
_ConnectionPtr ADOConn;
};

extern CDB1App theApp;

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_DB1_H__ADCF8416_55EA_4533_A352_5688D57F0D60__INCLUDED_)



DB1.cpp
///////////////////////////////////////
#include "stdafx.h"
#include "DB1.h"

#include "MainFrm.h"
#include "DB1Doc.h"
#include "DB1View.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDB1App

BEGIN_MESSAGE_MAP(CDB1App, CWinApp)
//{{AFX_MSG_MAP(CDB1App)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDB1App construction

CDB1App::CDB1App()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CDB1App object

CDB1App theApp;

/////////////////////////////////////////////////////////////////////////////
// CDB1App initialization

BOOL CDB1App::InitInstance()
{
// Initialize OLE libraries
if (!AfxOleInit())
{
AfxMessageBox(IDP_OLE_INIT_FAILED);
return FALSE;
}

AfxEnableControlContainer();

// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.

#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif

// Create ADO Connection
if( FAILED(::CoInitialize(NULL)) )
{
AfxMessageBox("ADO Init failed");
return false;
}
try
{
ADOConn.CreateInstance(__uuidof(Connection));
ADOConn->Open("DSN=Hotel_MIS;User ID=Administrator;pwd=fhz;Provider=MSDASQL","","", adConnectUnspecified);

}
// Catch Exceptions
catch(_com_error &e)
{
CString err;
err.Format("%s", (char*)(e.Description()) );
AfxMessageBox(err);
}
catch(...)
{
AfxMessageBox("Unknown Error...");
}

// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));

LoadStdProfileSettings(); // Load standard INI file options (including MRU)

// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.

CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CDB1Doc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CDB1View));
pDocTemplate->SetContainerInfo(IDR_CNTR_INPLACE);
AddDocTemplate(pDocTemplate);

// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);

// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;

// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->SetWindowText(_T("数据库实验程序"));
m_pMainWnd->UpdateWindow();

return TRUE;
}


/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
CAboutDlg();

// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA

// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
// No message handlers
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

// App command to run the dialog
void CDB1App::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CDB1App message handlers


bool CDB1App::ADOExecute(_RecordsetPtr &ADO, _variant_t &strSQL)
{
if ( ADO->State == adStateOpen) ADO->Close();
try
{
ADO->Open(strSQL, ADOConn.GetInterfacePtr(), adOpenStatic, adLockOptimistic, adCmdUnknown);
return true;
}
catch(_com_error &e)
{
CString err;
err.Format("ADO Error: %s",(char*)e.Description());
AfxMessageBox(err);
return false;
}
}

int CDB1App::ExitInstance()
{
// TODO: Add your specialized code here and/or call the base class
if (adStateOpen == ADOConn->State) ADOConn->Close(); //释放ADO Connection
ADOConn->Release();
if (adStateOpen == m_pADORecord->State) m_pADORecord->Close(); //释放ADO RecordSet
m_pADORecord->Release();
return CWinApp::ExitInstance();
}
fanzai 2003-08-21
  • 打赏
  • 举报
回复
CDB1App 是如何定义的?
如果可以把程序贴出来看看。
phoenixsoft 2003-08-21
  • 打赏
  • 举报
回复
我调试了一下,发现在运行到这个if语句时:
if (theApp.ADOExecute(theApp.m_pADORecord,strQuery))

弹出以下的错误提示:
Unhandled exception in DB1.exe(KERNEL32.DLL):0xE06D7363:Microsoft C++ exception
点击OK后跳到一个汇编语言的调试窗口。

我在这个程序的App类中这样定义了theApp :
extern CDB1App theApp;

ADOExecute(theApp.m_pADORecord,strQuery)是CDB1App类的成员函数,功能是进行数据库操作。

大家帮我看看有什么问题?
phoenixsoft 2003-08-21
  • 打赏
  • 举报
回复
程序已经贴出来了,怎么没人看啊?
ForFar 2003-08-20
  • 打赏
  • 举报
回复
这样的错误一般都是非法访问内存引起的,一步步单步调试跟踪下去,看看指针或数组有无反问违例。
bluestar 2003-08-20
  • 打赏
  • 举报
回复
单击OK按钮的消息处理函数中设断点,一步一步看看哪里出错。
fireant25 2003-08-20
  • 打赏
  • 举报
回复
可能是数据库连接或者数据库操作导致的错误。

你可以用F9在OnOK函数里设置断点,然后
按F5开始调试,程序运行到断点处以后,你
可以按F10进行单步跟踪。
sunheroshang 2003-08-20
  • 打赏
  • 举报
回复
build->start dubug->go
调出你的对话框,操作,找到发生错误的位置
或者在OnOk处设定断点后调试
smch 2003-08-20
  • 打赏
  • 举报
回复

try
{
}
catch
{
}
捕捉错误。否则你这样的程序投入正常使用就麻烦了。
netrouter 2003-08-20
  • 打赏
  • 举报
回复
如果你是用VC6.0,我想你需要首先应该对VC的Debug功能进行一些了解。
比如,一些VC的入门读物或者看看MSDN了解VC如何进行Debug。

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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