Microsoft KB Archive/270638

= BUG: Database Compaction with SQLConfigDataSource Fails when Access Database is Password Protected =

Article ID: 270638

Article Last Modified on 9/17/2003

-

APPLIES TO


 * Microsoft Open Database Connectivity Driver for Access 4.0
 * Microsoft Open Database Connectivity Driver for Access 3.0
 * Microsoft Open Database Connectivity Driver for Access 3.4
 * Microsoft Open Database Connectivity Driver for Access 3.5
 * Microsoft Open Database Connectivity Driver for Access 3.6

-



This article was previously published under Q270638



SYMPTOMS
When a Microsoft Access database is password protected, attempts to compact the database using the SQLConfigDataSource ODBC API might fail with the following error message:

&quot;Not a valid password&quot;

The error message occurs even if you specify the password information in the Attributes list as follows: SQLConfigDataSource(NULL,ODBC_ADD_DSN,(LPSTR)&quot;Microsoft Access Driver (*.mdb)&quot;,                   &quot;COMPACT_DB=C:\\MDB\\Sample.mdb C:\\MDB\\CompatedSample.mdb General\0&quot;                    &quot;PWD=WSG\0DataDirectory=C:\\MDB\0MaxScanRows=20\0\0&quot;);



RESOLUTION
To work around this problem, use the Microsoft OLE DB Provider for Jet or Data Access Objects (DAO) directly and bypass the Microsoft Access ODBC Driver.

Samples follow that show how to achieve this functionality:

  Microsoft Visual Basic sample using the Microsoft OLE DB Provider for Jet and Microsoft Jet and Replication Objects (JRO): Private Sub Command1_Click Dim myJRO As New jro.JetEngine

myJRO.CompactDatabase &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\mymdb\\sample.mdb;Jet OLEDB:Database Password=YourPassword;&quot;, _ &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\mymdb\\compactedSample.mdb;Jet OLEDB:Engine Type=5; Jet OLEDB:Database Password=YourPassword;&quot; End Sub

  Microsoft Visual C++ sample using Microsoft Foundation Classes (MFC) DAO classes:

This is a standard Microsoft Visual C++ application that supports MFC.

static char THIS_FILE[] = __FILE__;
 * 1) ifdef _DEBUG
 * 2) define new DEBUG_NEW
 * 3) undef THIS_FILE
 * 1) endif

///////////////////////////////////////////////////////////////////////////// // The one and only application object

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) {   int nRetCode = 0;

// initialize MFC and print and error on failure if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine, 0)) {       // TODO: change error code to suit your needs cerr << _T(&quot;Fatal Error: MFC initialization failed&quot;) << endl; nRetCode = 1; }   else {      CDaoDatabase db; try{ db.m_pWorkspace->CompactDatabase(_T(&quot;C:\\MyMDB\\Sample.mdb&quot;),                                                 _T(&quot;C:\\MyMDB\\CompactedSample.mdb&quot;),dbLangGeneral,dbVersion30,&quot;;pwd=YourPassword&quot;); }      catch (CDaoException *e) {           AfxMessageBox (e->m_pErrorInfo->m_strDescription); e->Delete; }      return nRetCode; } } 



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



MORE INFORMATION
