如题 这应该检查哪儿的代码呢?谢谢!!各位高手!请指教!
初始化为:BOOL CZXXGVAApp::InitInstance()
{
AfxEnableControlContainer();
CoInitialize(NULL);
// 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.
//初始化SkinLoad,加载皮肤文件
//InitSkinLoad(GetCurrentThreadId());
//LoadSkin("xp_silver.skin");//xp_normal
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif // 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(CZXXGVADoc),
RUNTIME_CLASS(CMainFrame),       // main SDI frame window
RUNTIME_CLASS(CZXXGVAView));
AddDocTemplate(pDocTemplate); // Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);

m_nCmdShow = SW_SHOWMAXIMIZED;
// 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->SetWindowText(_T("上海哈顿车辆监控系统"));

m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
CHAR szFileName[MAX_PATH];
GetModuleFileName(NULL,szFileName,MAX_PATH);

CString strPath(szFileName);
int nPos = strPath.ReverseFind('\\');

strPath = strPath.Left(nPos);
nPos = strPath.ReverseFind('\\');

strPath = strPath.Left(nPos);
strPath += _T("\\Debug\\ZXXDBC.ini"); CStdioFile file;
if(file.Open(strPath,CFile::modeRead))
{
CString strText;
file.ReadString(strText);
int nPos;
CString strLeft,strRight;
int nIndex = 0;
while(file.ReadString(strText))
{
nPos = strText.Find("=");
strLeft = strText.Left(nPos);
strLeft.TrimLeft();
strLeft.TrimRight();

strRight = strText.Mid(nPos+1);
strRight.TrimLeft();
strRight.TrimRight();

if ("SERVER"==strLeft)
SERVER=strRight;
if ("DATABASE"==strLeft)
DATABASE=strRight;
if ("UID"==strLeft)
UID=strRight;
if ("PWD"==strLeft)
PWD=strRight;

if (("ServerDBIP"==strLeft)&&(strRight!=""))
ServerDBIP=strRight;


nIndex++;
}
file.Close();
}
else 
{
AfxMessageBox("数据库配置文件错误!");
return FALSE;
} /*
if(m_adoConnection.ConnectSQLServer(_T("CRE-GVA"),_T("Monitor"),_T("sa"),_T("123")))
{
m_adoRecordSet.SetAdoConnection(&m_adoConnection);
m_adoRecordSet.SetCursorLocation();
}
else
{
AfxMessageBox("数据库连接失败!");
}*/
return TRUE;
}

解决方案 »

  1.   

    这段代码应该没有问题。建立空文档失败大概是你的ADO连接出错了或者建立ADO数据库连接滞后了,而你在文档或者视图的初始化阶段又用到了数据库,注意建立连接的时机。
      

  2.   

    ADO连接应该放在哪儿呢?这是系统启动的时候就要的,那连接数据库在哪儿连接呢?
      

  3.   

    注意你在AddDocTemplate(pDocTemplate);之后才读取配置文件并建立调用ADO连接,其实系统在你pDocTemplate = new CSingleDocTemplate(...)时就已经开始进行框架,文档,视图的初始化工作了,如果你在任何一个有操作数据库的动作就会引起建立空文档失败。
    建议你在CMainFrame的OnCreate()中读取配置文件并建立数据库连接。
      

  4.   

    在CMainFrame的OnCreate()函数中已经连接数据库了啊~好象没问题吧???
      

  5.   

    还有就是在CMainFrame的OnCreate()函数和CView中的OnCreate()函数功能上有什么区别呢??这两个函数里面一般是应该写些什么代码?