Author Topic: Lisp to get items from MS Access 2010 (64bit)  (Read 13625 times)

0 Members and 1 Guest are viewing this topic.

BlackBox

  • King Gator
  • Posts: 3770
Re: Lisp to get items from MS Access 2010 (64bit)
« Reply #15 on: September 07, 2012, 05:06:18 PM »
Just curious... Have you considered simply using ADO .NET instead?  :?
"How we think determines what we do, and what we do determines what we get."

Rabbit

  • Guest
Re: Lisp to get items from MS Access 2010 (64bit)
« Reply #16 on: September 07, 2012, 06:04:25 PM »
ADO.NET looks like C# language.  I don't speak it.  But thanks for the idea.

owenwengerd

  • Bull Frog
  • Posts: 452
Re: Lisp to get items from MS Access 2010 (64bit)
« Reply #17 on: September 07, 2012, 08:51:47 PM »
Before you can administer the 64-bit ODBC driver, you have to install it. That will be your first challenge.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Lisp to get items from MS Access 2010 (64bit)
« Reply #18 on: September 10, 2012, 10:24:28 AM »
Unless you have software that is fully dependant on 32-bit Access, I recommend you re-install *everything* as 64-bit.  It will save you a host of future problems.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

Rabbit

  • Guest
Re: Lisp to get items from MS Access 2010 (64bit)
« Reply #19 on: September 10, 2012, 11:42:59 AM »
Okay, since I.T. would get highly pissed if I screw up the machine, I need to make sure of what I'm doing before I do it.  Best I can tell, I have to use the SysWOW version of odbcad32 before I do any calls using ADOLisp..  What I'm not sure of is, if I run this what else could it mess up, if any.  If I run that, would I need to follow up afterwards with a call to run the original version of odbcad32 in the System32 folder.

Rabbit

  • Guest
Re: Lisp to get items from MS Access 2010 (64bit)
« Reply #20 on: September 10, 2012, 11:46:47 AM »

LeeA,
What is ExpEnvStr?  Is that a subroutine?

Here is what I have done in the past:

Code - Auto/Visual Lisp: [Select]
  1. ;; Works with MDB Files MS Office 2007 and earlier
  2.   ;; Load the DAO Library
  3.   (if (= daoLibImport nil)
  4.     (progn
  5.       (vlax-import-type-library :tlb-filename (strcat strProgramFiles "\\Common Files\\Microsoft Shared\\DAO\\dao360.dll")
  6.                                 :methods-prefix "daom-"
  7.                                 :properties-prefix "daop-"
  8.                                 :constants-prefix "daoc-"
  9.       )
  10.       (setq daoLibImport T)
  11.     )
  12.   )
  13.  
  14.   ;; Create a reference to the Database engine
  15.   (setq daoObj (vlax-create-object "DAO.DBEngine.36"))
  16.  
  17.   ;; Open the database
  18.   (setq dbObj (daom-opendatabase daoObj "C:\\Datasets\\mydata.mdb"))
  19.  
  20.  
  21. ;; Works with MS Office 2007 and later
  22.   ;; Load the ADO library
  23.   (if (= adoLibImport nil)
  24.     (progn
  25.       (vlax-import-type-library :tlb-filename (strcat (ExpEnvStr "%PROGRAMFILES%") "\\Common Files\\System\\ado\\msado15.dll")
  26.                                 :methods-prefix "adom-"
  27.                                 :properties-prefix "adop-"
  28.                                 :constants-prefix "adoc-"
  29.       )
  30.       (setq adoLibImport T)
  31.     )
  32.   )
  33.  
  34.   ;; Create a recordset and connection object
  35.   (setq adoRecordset (vlax-create-object "ADODB.Recordset"))
  36.   (setq adoConnection (vlax-create-object "ADODB.Connection"))
  37.  
  38.   (setq strConnection (strcat "Provider=Microsoft.ACE.OLEDB.12.0;"
  39.                               "Data Source=C:\\Datasets\\mydata.mdb;"
  40.                               "Jet OLEDB:Database Password=;"))
  41.  
  42.   ;; Open the database
  43.   (adom-open adoConnection strConnection "" nil nil)

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Lisp to get items from MS Access 2010 (64bit)
« Reply #21 on: September 10, 2012, 12:00:45 PM »
What is ExpEnvStr?

I'm guessing it looks something like this:

Code - Auto/Visual Lisp: [Select]
  1. (defun expenvstr ( str / res wsh )
  2.     (if (setq wsh (vlax-create-object "wscript.shell"))
  3.         (progn
  4.             (setq res (vl-catch-all-apply 'vlax-invoke (list wsh 'expandenvironmentstrings str)))
  5.             (vlax-release-object wsh)
  6.             (if (null (vl-catch-all-error-p res))
  7.                 res
  8.             )
  9.         )
  10.     )
  11. )

8)

Rabbit

  • Guest
Re: Lisp to get items from MS Access 2010 (64bit)
« Reply #22 on: September 10, 2012, 01:01:02 PM »
Well LeeA,  when I use your code, I get the error: 

For
(vlax-import-type-library :tlb-filename (strcat (ExpEnvStr "%PROGRAMFILES%") "\\Common Files\\System\\ado\\msado15.dll")
        :methods-prefix "adom-"
        :properties-prefix "adop-"
        :constants-prefix "adoc-"
      )
I get
User warning: assignment to protected symbol: adom-AddNew <- #<SUBR @000000002ea0d930 nil>

And for
(adom-open adoConnection strConnection "" nil nil)
I get
; error: Automation Error. Provider cannot be found. It may not be properly installed.

Rabbit

  • Guest
Re: Lisp to get items from MS Access 2010 (64bit)
« Reply #23 on: September 10, 2012, 02:35:31 PM »
I decided to open up the SysWOW64/odbcad32.exe.  Now I'm in waaaaaaaay over my head.  I have no idea what I'm doing here.  I thought that it was supposed to set up the drivers automatically, but instead I get a window in which to set up everything manually.  I'm lost now.

owenwengerd

  • Bull Frog
  • Posts: 452
Re: Lisp to get items from MS Access 2010 (64bit)
« Reply #24 on: September 10, 2012, 02:54:35 PM »
You have to install the 64 bit Access ODBC drivers before you can configure it.

Rabbit

  • Guest
Re: Lisp to get items from MS Access 2010 (64bit)
« Reply #25 on: September 10, 2012, 04:11:19 PM »
Looks likeI'm going to have to abandon this whole undertaking.  I've stepped outside of my comfort zone.  When I go to install the 64 bit drivers, I get a message saying I need to uninstall Access 2010 32 bit and reinstall using 64 bit.  This is something I would have to do for evry machine, which is a total PITA.  Plus, this is starting to get into items that I have not the first idea of how to use.  SQL server is one and the whole odbcad32.exe crap.  I've spent hours trying to research this with no luck.  There are tons of posts where people are asking about this and none give a simple answer as how to get it working.  Owen and LeeA, I appreciate your help.  You guys are either going to have to point me to somewhere to get the code to extract information from Access or do it for me.  I'm in this far beyond my capibilities.

From the ADOLisp_Eample.lsp file I need everything from

(defun C:Example (/ ConnectionObject Result ConnectString SQLStatement
                  TablesList ColumnsList
                 )

to

(if (not (setq ConnectionObject
                  (ADOLISP_ConnectToDB ConnectString "admin" "")
           )
      )

this is everything I've tried:

 (defun expenvstr ( str / res wsh )
    (if (setq wsh (vlax-create-object "wscript.shell"))
      (progn
   (setq res (vl-catch-all-apply 'vlax-invoke (list wsh 'expandenvironmentstrings str)))
   (vlax-release-object wsh)
   (if (null (vl-catch-all-error-p res))
     res
   );if
      );progn
    );if
  );defun


  (if (= adoLibImport nil)
    (progn
      (vlax-import-type-library :tlb-filename (strcat (ExpEnvStr "%PROGRAMFILES%") "\\Common Files\\System\\ado\\msado15.dll")
        :methods-prefix "adom-"
        :properties-prefix "adop-"
        :constants-prefix "adoc-"
      )
      (setq adoLibImport T)
      )
    )
  ;; Create a recordset and connection object
  (setq adoRecordset (vlax-create-object "ADODB.Recordset"))
  (setq adoConnection (vlax-create-object "ADODB.Connection"))
  (setq strConnection (strcat "Provider=Microsoft.ACE.OLEDB.12.0;"
               "User ID=Admin;"
               "Data Source=G:\\FHU_CAD Operations\\FRANKE_CAD\\Schedules\\2011 MCD\\MASTER.mdb;"
               "Jet OLEDB:Database Password=;"))
  ;; Open the database
  (adom-open adoConnection strConnection "" nil nil)

  ;;;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  (setq oAccessApp (vlax-get-or-create-object "Access.Application"))
  (setq oAccessApp (vl-catch-all-apply 'vlax-release-object (list oAccessApp)))

   ;;;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  ;; Connecting to the database ...
  (setq ConnectString
         "Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=G:\\FHU_CAD Operations\\FRANKE_CAD\\Schedules\\2011 MCD\\MASTER.mdb;Mode=Share Deny Write
         ;Extended Properties=\"\";Jet OLEDB:System database=\"\";Jet OLEDB:Registry Path=\"\";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=0
         ;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password=\"\";Jet OLEDB:Create System Database=False
         ;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False
         ;Jet OLEDB:Support Complex Data=False;Jet OLEDB:Bypass UserInfo Validation=False"
  )
 
 ;;;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  (ADOLISP_ConnectToDB
    "Driver={Microsoft Access Driver (*.mdb)};Dbq=G:\\FHU_CAD Operations\\FRANKE_CAD\\Schedules\\2011 MCD\\MASTER.mdb;ID=Admin;Pwd=\"\";"  "Admin" "")

;;;--------------------------------------------------------------------------------------------
  (ADOLISP_ConnectToDB "Driver={Microsoft Access Driver (*.mdb)};DBQ=G:\\FHU_CAD Operations\\FRANKE_CAD\\Schedules\\2011 MCD\\MASTER.mdb" "Admin" "")

;;;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  (defun adoconnect (fn / ccname processor_type)
 (setq processor_type (getenv "processor_architecture"))
 (if (= processor_type "AMD64")
  (setq ccname (ADOLISP_ConnectToDB "Driver={Microsoft Access Driver (*.mdb)};DBQ=G:\\FHU_CAD Operations\\FRANKE_CAD\\Schedules\\2011 MCD\\MASTER.mdb;Uid=Admin;Pwd=;\"\"" "admin" ""))
  (setq ccname (ADOLISP_ConnectToDB (strcat "Provider=Microsoft.JET.OLEDB.4.0;Data Source=" "G:\\FHU_CAD Operations\\FRANKE_CAD\\Schedules\\2011 MCD\\MASTER.mdb" ";Persist Security Info=False") "admin" ""))
 )
 ccname
)

I just don't know where to go from here.

Thanks again,
Rabbit

HYPERPICS

  • Guest
Re: Lisp to get items from MS Access 2010 (64bit)
« Reply #26 on: September 20, 2012, 06:01:39 PM »
Here is more from what I showed at AU 2011.

Code - Auto/Visual Lisp: [Select]
  1. ;; Load COM environment
  2.  
  3. ;; Shows how to use expanding environment strings
  4. ;; Usage: (ExpEnvStr "%TEMP%\\MYDATA")
  5. ;; Results of sample: "C:\\DOCUME~1\\Lee\\LOCALS~1\\Temp\\MYDATA"
  6. (defun ExpEnvStr ( strVal / wshShell strValRet)
  7.   ;; Create reference to Window Scripting Shell Object
  8.   (setq wshShell (vlax-create-object "WScript.Shell"))
  9.  
  10.   ;; Expand the string and any variables in the string
  11.   (setq strValRet (vlax-invoke-method wshShell 'ExpandEnvironmentStrings strVal))
  12.  
  13.   ;; Release the Window Scripting Shell Object
  14.   (vlax-release-object wshShell)
  15.  
  16.   strValRet
  17. )
  18.  
  19.  
  20. ;; Get Program Files Folder
  21. ;; (setq strProgramFiles (ExpEnvStr "%PROGRAMFILES(X86)%"))
  22. (setq strProgramFiles (ExpEnvStr "%PROGRAMFILES%"))
  23.  
  24. ;; Global path for Microsoft Office
  25.   ;; Check for Microsoft Office 2010 (Office14)
  26.   ((/= (findfile (strcat strProgramFiles "\\Microsoft Office\\Office14")) nil)
  27.       (setq strMSOfficePath (strcat strProgramFiles "\\Microsoft Office\\Office14\\")
  28.             strOfficeVer "14"
  29.       )
  30.   )
  31.   ;; Check for Microsoft Office 2007 (Office12)
  32.   ((/= (findfile (strcat strProgramFiles "\\Microsoft Office\\Office12")) nil)
  33.       (setq strMSOfficePath (strcat strProgramFiles "\\Microsoft Office\\Office12\\")
  34.             strOfficeVer "12"
  35.       )
  36.   )
  37.   ;; Check for Microsoft Office 2003 (Office11)
  38.   ((/= (findfile (strcat strProgramFiles "\\Microsoft Office\\Office11")) nil)
  39.       (setq strMSOfficePath (strcat strProgramFiles "\\Microsoft Office\\Office11\\")
  40.             strOfficeVer "11"
  41.       )
  42.   )
  43.   ;; Check for Microsoft Office 2000 (Office10)
  44.   ((/= (findfile (strcat strProgramFiles "\\Microsoft Office\\Office10")) nil)
  45.       (setq strMSOfficePath (strcat strProgramFiles "\\Microsoft Office\\Office10\\")
  46.             strOfficeVer "10"
  47.       )
  48.   )
  49.   (setq strMSOfficePath "" strOfficeVer "")
  50. )
  51.  
  52. ;; Opens an Access Database file and reports on the number of records in a table and
  53. ;; the records contained in the table.
  54.  
  55. ;; Works with MDB Files MS Office 2007 and earlier
  56. (defun c:AccessDatabase ( / daoObj dbObj rstObj fieldsObj)
  57.  
  58.   ;; Load the DAO Library
  59.   (if (= daoLibImport nil)
  60.     (progn
  61.       (vlax-import-type-library :tlb-filename (strcat strProgramFiles "\\Common Files\\Microsoft Shared\\DAO\\dao360.dll")
  62.                                 :methods-prefix "daom-"
  63.                                 :properties-prefix "daop-"
  64.                                 :constants-prefix "daoc-"
  65.       )
  66.       (setq daoLibImport T)
  67.     )
  68.   )
  69.  
  70.   ;; Create a reference to the Database engine
  71.   (setq daoObj (vlax-create-object "DAO.DBEngine.36"))
  72.  
  73.   ;; Open the database
  74.   (setq dbObj (daom-opendatabase daoObj "C:\\Datasets\\CP417-7\\data files\\AU2011.mdb"))
  75.  
  76.   ;; Open the table
  77.   (setq rstObj (daom-openrecordset dbObj "tblEmployees" daoc-dbOpenDynaset)) ;;daoc-dbOpenDynaset daoc-dbOpenTable
  78.  
  79.   ;; Step to the first and then last record to get the number of records in the table
  80.   (daom-movefirst rstobj)
  81.   (daom-movelast rstobj 0)
  82.   (prompt (strcat "\n" (itoa (daop-get-recordcount rstObj)) " records in table."))
  83.  
  84.   ;; Step back to the first record
  85.   (daom-movefirst rstobj)
  86.   (prompt "\n\nEmployee names")
  87.  
  88.   ;; Report each of the records that are in the table
  89.   (while (= (daop-get-eof rstObj) :vlax-false)
  90.     (setq fieldsObj (daop-get-fields rstObj))
  91.    
  92.     (prompt (strcat "\nFirst name: " (vlax-variant-value (daop-get-value (daop-get-item fieldsObj "FirstName")))))
  93.     (prompt (strcat "\nLast name: " (vlax-variant-value (daop-get-value (daop-get-item fieldsObj "LastName")))))
  94.     (terpri)
  95.  
  96.     ;; Move to the next record
  97.     (daom-movenext rstobj)
  98.   )
  99.  
  100.   ;; Do a search for the employee with the first name Bob
  101.   (daom-movefirst rstobj)
  102.   (daom-findfirst rstobj "FirstName='Bob'")
  103.  
  104.   ;; If the record is found them return some information about the record
  105.   (if (= (daop-get-nomatch rstobj) :vlax-true)
  106.     (prompt "\nNo matching record")
  107.     (progn
  108.       (setq fieldsObj (daop-get-fields rstobj))
  109.       (prompt (strcat "\nBob was in room " (vlax-variant-value (daop-get-value (daop-get-item fieldsObj "RoomNumber")))))
  110.       (terpri)
  111.  
  112.       ;; Open the record for edit
  113.       (daom-edit rstobj)
  114.  
  115.       ;; Change the value of the RoomNumber field
  116.       (daop-put-value (daop-get-item fieldsObj "RoomNumber") "103A")
  117.  
  118.       ;; Inform of record change
  119.       (prompt "but is now in room 103A.\n")
  120.  
  121.       ;; Update the record
  122.       (daom-update rstobj 1 0)
  123.      (princ)
  124.     )
  125.   )
  126.  
  127.   ;; Close the recordset and database
  128.   (daom-close rstobj)
  129.   (daom-close dbObj)
  130.  
  131.   ;; Release the DAO object
  132.   (gc)
  133.  (princ)
  134. )
  135.  
  136.  
  137. ;; Works with MS Office 2007 and later
  138. (defun c:AccessDatabaseADO ( / daoObj dbObj rstObj fieldsObj)
  139.  
  140.   ;; Load the ADO library
  141.   (if (= adoLibImport nil)
  142.     (progn
  143.       (vlax-import-type-library :tlb-filename (strcat (ExpEnvStr "%PROGRAMFILES%") "\\Common Files\\System\\ado\\msado15.dll")
  144.                                 :methods-prefix "adom-"
  145.                                 :properties-prefix "adop-"
  146.                                 :constants-prefix "adoc-"
  147.       )
  148.       (setq adoLibImport T)
  149.     )
  150.   )
  151.  
  152.   ;; Create a recordset and connection object
  153.   (setq adoRecordset (vlax-create-object "ADODB.Recordset"))
  154.   (setq adoConnection (vlax-create-object "ADODB.Connection"))
  155.  
  156.   (setq strConnection (strcat "Provider=Microsoft.ACE.OLEDB.12.0;"
  157.                               "Data Source=C:\\Datasets\\CP417-7\\data files\\AU2011.mdb;"
  158.                               "Jet OLEDB:Database Password=;"))
  159.  
  160.   ;; Open the database
  161.   (adom-open adoConnection strConnection "" nil nil)
  162.  
  163.   ;; Open the table
  164.   (adom-open adoRecordset "tblEmployees" adoConnection adoc-adOpenKeyset adoc-adLockOptimistic adoc-adCmdTable)
  165.  
  166.   ;; Step to the first and then last record to get the number of records in the table
  167.   (adom-MoveFirst adoRecordset)
  168.   (adom-MoveLast adoRecordset)
  169.   (prompt (strcat "\n" (itoa (adop-get-RecordCount adoRecordset)) " records in table."))
  170.  
  171.   ;; Step back to the first record
  172.   (adom-MoveFirst adoRecordset)
  173.   (prompt "\n\nEmployee names")
  174.  
  175.   ;; Report each of the records that are in the table
  176.   (while (= (adop-get-eof adoRecordset) :vlax-false)
  177.     (setq fieldsObj (adop-get-fields adoRecordset))
  178.    
  179.     (prompt (strcat "\nFirst name: " (vlax-variant-value (adop-get-value (adop-get-item fieldsObj "FirstName")))))    (prompt (strcat "\nLast name: " (vlax-variant-value (adop-get-value (adop-get-item fieldsObj "LastName")))))
  180.     (terpri)
  181.  
  182.     ;; Move to the next record
  183.     (adom-movenext adoRecordset)
  184.   )
  185.  
  186.   ;; Do a search for the employee with the first name Bob
  187.   (adom-movefirst adoRecordset)
  188.   (adom-Find adoRecordset "FirstName = 'Bob'" 0 adoc-adSearchForward 1)
  189.  
  190.   ;; If the record is found them return some information about the record
  191.   (if (= (adop-get-eof adoRecordset) :vlax-true)
  192.     (prompt "\nNo matching record")
  193.     (progn
  194.       (setq fieldsObj (adop-get-fields adoRecordset))
  195.       (prompt (strcat "\nBob was in room " (vlax-variant-value (adop-get-value (adop-get-item fieldsObj "RoomNumber")))))
  196.       (terpri)
  197.  
  198.       ;; Change the value of the RoomNumber field
  199.       (adop-put-value (adop-get-item fieldsObj "RoomNumber") "103A")
  200.  
  201.       ;; Inform of record change
  202.       (prompt "but is now in room 103A.\n")
  203.  
  204.       ;; Update the record
  205.       (adom-update adoRecordset)
  206.      (princ)
  207.     )
  208.   )
  209.  
  210.   ;; Close the recordset and database
  211.   (adom-close adoRecordset)
  212.   (adom-close adoConnection)
  213.  
  214.   (vlax-release-object adoRecordset)
  215.   (vlax-release-object adoConnection)
  216.  
  217.   (gc)
  218.  (princ)
  219. )