Home > Database > Mysql Tutorial > body text

access 数据库自启动困难解决方法

WBOY
Release: 2016-06-07 18:07:24
Original
889 people have browsed it

这几天考试之余,闲来无事,发现所做程序自启动的access数据库连接错误, 而启动后重新打开文件就可以正常连接数据库.

问题分析好久,
经过排查,问题在于数据库的启动路径有问题,在连接数据库 时候可以这样写
GetModuleFileName(NULL,path,255);//获得自启动的程序完整路径;
CString str;
str.Format("%s",path);
int place;
place = str.ReverseFind( '\\' ); //获得最后一个'\'的位置;
CString db_name;
db_name = str.Left(place+1) + "qijian.mdb"; //整合出access数据库完整路径
CString connect; //连接的第一个参数
connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + db_name + ";";
hr = theApp.m_pConnection->Openconnect.GetBuffer(connect.GetLength()),"","",adModeUnknown); //参数带入并连接
其余代码不必多改 .
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template