VC + ADO + Access2000 Database File Password Setup and Modification

xiaoxiao2021-03-06  51

VC ADO Access2000 Database File Password Setup and Modification In the nearest application, I have asked a lot of netizens to give * .mdb file encryption code, the problem is finally resolved. I put it out of the way, I hope everyone will correct it.

1. Add a password to a database without a password: hr = m_pconnection-> open ("provider = microsoft.jet.Oledb.4.0; user ID = admin; data source = d: //db//remo.mdb; mode = share deny read "", "," ", 0); m_pconnection-> execute (" ALTER DATABASE Password [123] null, null, adcmdtext); The above is to set the password 1232. Change the password 123 to 456: hr = m_pConnection-> open ("provider = microsoft.jet.Oledb.4.0; user id = admin; data source = d: //db//remo.mdb; jet oledb: Database password = Sanycom; Mode = Share deny Read | Share deny Write ",", "", 0); M_PConnection-> Execute ("Alter Database Password [456] [123]", NULL, ADCMDTEXT); Note and 1. Different: Many password parts in the first parameter of Open, so that the database can be developed normally

Note: Data Source = full path / file name in the first parameter in Open. MDB (no full path Open failed) 3. Accessing a password database method 1: hr = m_pConnection-> Open ("DSN = REMO", "Admin", "456", 0); // wherein REMO is a data source, the appropriate data source exists, of course, if Open Failure can reset the data source (see later) method 2: hr = m_pConnection-> open ("provider = microsoft.jet.OleDb.4.0; user ID = admin; data source = d: //db//remo.mdb; Jet OLEDB: Database Password = 456; Mode = Share Deny Read | Share Deny Write ",", "", 0); Note: The second, 3 parameters are empty, the parameter value is already in the first parameter, Disadvantages: The data source location is written in the program, it is not good, it is best to dynamically obtain the database file location, and it is very convenient to use getModuleFileName (). 4. To set up a data source in the program: // Set the location of the database file on the previous directory of SMC // ------------------------ -------------------------------- CString Spath; // Get the full path and program name getModuleFileName ( NULL, Spath.getBuffersetlength (MAX_PATH 1), MAX_PATH); Spath.ReleaseBuffer (); // afxMessageBox (spath); int NPOS; npos = spath.reverseFind ('' '//'); spath = spath.left Npos); // npos = spath.reversefind ('' // '); // spath = spath.left (npos); // Get the path of the database file and file name cstring lpszfile = spath "// Remo. MDB "; m_strfilepath = lpszfile; char * szdesc; int mlen; szdesc = new char [256]; sprintf (szdesc," dsn =% s? description = remote car control data source? DBQ =% s? FIL = Microsoft Access? defaultdir =% s ?? "," remo ", lpszfile, spath); // afxMessageBox (szdesc); mlen = strlen (szdesc); for (int i = 0; i

// afxMessageBox (SZDESC); if (false == sqlconfigDataSource (NULL, ODBC_ADD_SYS_DSN, "Microsoft Access Driver (* .mdb) / 0", (LPTSTR) SZDESC) {MessageBox ("Create data source failed, the program will exit. Manually set the data source. " MAX_PATH]; GetWindowsDirectory (cWinPath, MAX_PATH); CString strWinPath = (CString) cWinPath "//system32//odbcad32.exe"; try {WinExec (strWinPath, 1);} catch (_com_error e) {AfxMessageBox (e.Description ());} //---2004.6.7--Add---end-// postquitMessage (0);} delete szdesc; Configuring Data Source Functions SQLConfigDataSource () requires #include support.

Also, join the ODBCCP32.lib library file

转载请注明原文地址:https://www.9cbs.com/read-83094.html

New Post(0)