TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: FELIX on April 15, 2017, 07:12:32 PM

Title: Error open MDB ADO Connection
Post by: FELIX on April 15, 2017, 07:12:32 PM
Code: [Select]
(vl-load-com)
 (setq ADOConnect   (vlax-create-object "ADODB.Connection")
       ADORecordset (vlax-create-object "ADODB.Recordset")
 ) ;_  setq
 (vlax-invoke-method ADOConnect
                     "Open"
                     (strcat "Driver={Microsoft Access Driver (*.mdb)};DBQ=" file)
                     "Admin"
                     ""
                     0
 )

error: Automation Error. [Microsoft][ODBC Driver Manager]
Data source name not found and no default driver specified
?
Title: Re: Error open MDB ADO Connection
Post by: kdub_nz on April 15, 2017, 07:51:34 PM
What is the value of the 'file' variable ??

(strcat "Driver={Microsoft Access Driver (*.mdb)};DBQ=" file)
Title: Re: Error open MDB ADO Connection
Post by: FELIX on April 15, 2017, 09:04:38 PM
Is the first time I use access to an mdb in VisualLisp. If you have another suggestion, thank you.

Code: [Select]
(vl-load-com)
(setq fn (findfile "d:\\test.mdb"))
(setq processor_type (getenv "processor_architecture"))
(if (= processor_type "AMD64")
  (setq strconn (STRCAT "Provider=MSDASQL;Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" fn))
  (setq strconn (strcat "Provider=Microsoft.JET.OLEDB.4.0;Data Source=" fn ";Persist Security Info=False"))
)
(setq ADOConnect   (vlax-create-object "ADODB.Connection")
      ADORecordset (vlax-create-object "ADODB.Recordset")
)
(vlax-invoke-method ADOConnect "Open" strconn "Admin" "" 0)
Title: Re: Error open MDB ADO Connection
Post by: roy_043 on April 16, 2017, 08:05:14 AM
Maybe this helps:
For the connection string I use:
Code: [Select]
(strcat
  (if (vl-registry-read "HKEY_CLASSES_ROOT\\Microsoft.ACE.OLEDB.12.0")
    "Provider=Microsoft.ACE.OLEDB.12.0;"
    "Provider=Microsoft.Jet.OLEDB.4.0;"
  )
  "Data Source="
  fileName
  ";"
  "Persist Security Info=False;"
)
Title: Re: Error open MDB ADO Connection
Post by: dgorsman on April 17, 2017, 10:27:32 AM
What version and bit-ness of Office do you have installed?  I'm assuming x64 AutoCAD; if you have Office 2010 it cannot be x32 (some have been able to install the x64 Access drivers alongside but I've always had problems).  Generally best if you install x64 Office, unless you have other applications which are dependent on the x32 Access drivers.
Title: Re: Error open MDB ADO Connection
Post by: FELIX on April 17, 2017, 03:59:10 PM
It worked. Thank you all.