title: Python ADO + ODBC function
body: <p>I am writing a small module to help a transfer from M$-Access to SQLite (database needs to be portable), but I'm struggling in interpreting the error message that follows from this code (and of course to get it to work). </p>
  
  <pre><code>import pyodbc
  import win32com.client
  
  def ado(db, sqlstring='select * from table', user='admin', password=''):
      conn = win32com.client.Dispatch(r'ADODB.Connection')
      DSN = ('PROVIDER = Microsoft.Jet.OLEDB.4.0;DATA SOURCE = ' + db +  ';')
      conn.Open(DSN)
      rs = win32com.client.Dispatch(r'ADODB.Recordset')
      rs.Open(strsql, conn, 1, 3)
      data = rs.GetRows()
      conn.Close()
      return data
  
  def odbc(db, sqlstring='select * from table', user= 'admin', password=''):
      """Create function for connecting to Access databases."""
      odbc_conn_str = 'DRIVER={Microsoft Access Driver (*.mdb)};DBQ=%s;UID=%s;PWD=%s' % (db, user, password)
      conn = pyodbc.connect(odbc_conn_str)
      cur = conn.cursor()
      cur.execute(strsql)
      data = list(cur)
      conn.close()
      return data
  
  if __name__ == '__main__': # Unit test       
      db = r'C:\pyodbc_access2007_sample.accdb'
      sql="select * from Customer Orders" ## tables: 'Customer Orders', 'Physical Stoks','Prodplans'
      data1 = ado(db,sql)
      data2 = odbc(db,sql)
  </code></pre>
  
  <p>From the ado function I get the error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:/pyodbc_access2007_example.py", line 27, in &lt;module&gt;
      data1 = ado(db,sql)
    File "C:/pyodbc_access2007_example.py", line 7, in ado
      conn.Open(DSN)
    File "&lt;COMObject ADODB.Connection&gt;", line 3, in Open
    File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 282, in _ApplyTypes_
      result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)
  com_error: (-2147352567, 'Exception occurred.', (0, u'Microsoft JET Database Engine', u"Unrecognized database format 'C:\\pyodbc_access2007_sample.accdb'.", None, 5003049, -2147467259), None)
  </code></pre>
  
  <p>and from the odbc function I get the error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:/pyodbc_access2007_example.py", line 28, in &lt;module&gt;
      data2 = odbc(db,sql)
    File "C:/pyodbc_access2007_example.py", line 17, in odbc
      conn = pyodbc.connect(odbc_conn_str)
  Error: ('HY000', "[HY000] [Microsoft][ODBC Microsoft Access Driver] Cannot open database '(unknown)'.  It may not be a database that your application recognizes, or the file may be corrupt. (-1028) (SQLDriverConnect); [01000] [Microsoft][ODBC Microsoft Access Driver]General Warning Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x18c0 Thread 0xe70 DBC 0x379fe4 Jet'. (1); [01000] [Microsoft][ODBC Microsoft Access Driver]General Warning Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x18c0 Thread 0xe70 DBC 0x379fe4 Jet'. (1); [01000] [Microsoft][ODBC Microsoft Access Driver]General Warning Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x18c0 Thread 0xe70 DBC 0x379fe4 Jet'. (1); [01000] [Microsoft][ODBC Microsoft Access Driver]General Warning Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x18c0 Thread 0xe70 DBC 0x379fe4 Jet'. (1); [HY000] [Microsoft][ODBC Microsoft Access Driver] Cannot open database '(unknown)'.  It may not be a database that your application recognizes, or the file may be corrupt. (-1028)")
  </code></pre>
  
  <p>Any good idea's on how to read this?</p>