帮我看数据库的错误

shore1000 2006-05-16 11:18:51
BOOL CShoreApp::InitInstance()
{

CString sPath;
GetModuleFileName(NULL,sPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH);
sPath.ReleaseBuffer ();
int nPos;
nPos=sPath.ReverseFind ('\\');
sPath=sPath.Left (nPos);
nPos=sPath.ReverseFind('\\');
sPath=sPath.Left (nPos);
CString lpszFile = sPath + "\\shore.mdb";


char* szDesc;
int mlen;
szDesc=new char[256];
sprintf(szDesc,"DSN=%s? DESCRIPTION=TOC support source? DBQ=%s? FIL=MicrosoftAccess? DEFAULTDIR=%s?? ","shore",lpszFile,sPath);



mlen = strlen(szDesc);
for (int i=0; i<mlen; i++)
{
if (szDesc[i] == '?')
szDesc[i] = '\0';
}

if (FALSE == SQLConfigDataSource(NULL,ODBC_ADD_DSN,"Microsoft Access Driver (*.mdb)\0",(LPCSTR)szDesc))
AfxMessageBox("SQLConfigDataSource Failed");


try
{
CString strConnect;
strConnect.Format("DSN=shore;");
if(!m_DB.OpenEx(strConnect,CDatabase::useCursorLib))
{
AfxMessageBox("Unable to Connect to the Specified Data Source");
return FALSE ;
}
}
catch(CDBException *pE)
{
pE->ReportError();
pE->Delete();
return FALSE;
}
编译错误:
e:\shore\shore.h(42) : error C2146: syntax error : missing ';' before identifier 'm_DB'
e:\shore\shore.h(42) : error C2501: 'CDatabase' : missing storage-class or type specifiers
e:\shore\shore.h(42) : error C2501: 'm_DB' : missing storage-class or type specifiers
E:\shore\shore.cpp(78) : error C2065: 'm_DB' : undeclared identifier
E:\shore\shore.cpp(78) : error C2228: left of '.OpenEx' must have class/struct/union type
E:\shore\shore.cpp(78) : error C2653: 'CDatabase' : is not a class or namespace name
E:\shore\shore.cpp(78) : error C2065: 'useCursorLib' : undeclared identifier
E:\shore\shore.cpp(84) : error C2061: syntax error : identifier 'CDBException'
E:\shore\shore.cpp(84) : error C2310: catch handlers must specify one type
E:\shore\shore.cpp(86) : error C2065: 'pE' : undeclared identifier
E:\shore\shore.cpp(86) : error C2227: left of '->ReportError' must point to class/struct/union
E:\shore\shore.cpp(87) : error C2227: left of '->Delete' must point to class/struct/union
E:\shore\shore.cpp(92) : error C2317: 'try' block starting on line '75' has no catch handlers
Error executing cl.exe.

shore.exe - 13 error(s), 0 warning(s)

...全文
89 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
shore1000 2006-05-16
  • 打赏
  • 举报
回复
m_DB 怎么定义的?
public
CDatabase m_DB
少了ODBC的头文件。
是不是odbcinst.h.我加了,

一条晚起的虫 2006-05-16
  • 打赏
  • 举报
回复
少了ODBC的头文件。
jacklzw88 2006-05-16
  • 打赏
  • 举报
回复
m_DB 怎么定义的?
一条晚起的虫 2006-05-16
  • 打赏
  • 举报
回复
afxdb.h

4,011

社区成员

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

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