After the tests over the past few days, I had nothing to worry about. I found that the access database connection error was self-initiated by the program. After the program was started, I re-opened the file to connect to the database normally.
After the tests over the past few days, I had nothing to worry about. I found that the access database connection error was self-initiated by the program. After the program was started, I re-opened the file to connect to the database normally.
Problem Analysis for a long time,
After troubleshooting, the problem lies in the database startup path, which can be written when you connect to the database.
GetModuleFileName (NULL, path, 255); // obtain the complete path of the self-starting program;
CString str;
Str. Format ("% s", path );
Int place;
Place = str. ReverseFind ('\'); // obtain the position of the last;
CString db_name;
Db_name = str. Left (place + 1) + "qijian. mdb"; // integrate the full path of the access Database
CString connect; // The first connection parameter.
Connect = "Provider = Microsoft. Jet. OLEDB.4.0; Data Source =" + db_name + ";";
Hr = theApp. m_pConnection-> Openconnect. GetBuffer (connect. GetLength (), "", "", adModeUnknown); // input and connect Parameters
You do not need to modify other codes.