Highlighted
Absent Member.
Absent Member.
6765 views

[archive] Adodb

[Migrated content. Thread originally posted on 01 September 2006]

Has anyone attempted to use Microsoft's ADODB to access information? Anyone made it work? If so, would you be willing to share an example of how you did this?

Thanks,
Rob
0 Likes
24 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] Adodb


           CREATE  Connection       OF ADODB
                   HANDLE           IN hConnection.
           Create  Recordset        OF ADODB
                   HANDLE           IN hRecordset.
           STRING  "Driver={Microsoft Access Driver (*.mdb)};"
                   "Dbq=apiv2db.mdb;"
                   "DefaultDir=F:\APIV2\DocExamples\MSADO;"
                   "ReadOnly=False"
                   DELIMITED        BY SIZE INTO ConnStr.

           MODIFY  hConnection      @Open(ConnStr).
           INQUIRE hConnection      State IN WS-ConnStat.

           IF      WS-ConnStat      NOT = adStateOpen
                   GO TO            MAIN-900
                   END-IF.

      * This variant uses the connection as a basis for the selection
      *    MODIFY  hConnection      Execute("Select * from Contacts",
      *            WS-RecCount,     adCmdText)
      *            GIVING           hRecordset.
     
       
           MODIFY  hRecordset       MaxRecords = 100.
           MODIFY  hRecordset       @Open(
                   BY NAME Source   
                   "Select * FROM Contacts ORDER BY LastName",
                   BY NAME ActiveConnection hConnection,
                   BY NAME Options adCmdText).
           MODIFY  hRecordset       MoveFirst().
           INQUIRE hRecordset       EOF IN WS-ConnStat.
           PERFORM UNTIL            WS-ConnStat = -1
                                   
                   INQUIRE          hRecordSet
                                    fields::item("FirstName")::value
                                    IN WS-First
                                    fields::item("LastName")::value
                                    IN WS-Last

                   INITIALIZE       WS-String

                   STRING           WS-Last DELIMITED BY SPACE
                                    ", " DELIMITED BY SIZE
                                    WS-First DELIMITED BY SPACE
                                    INTO WS-String

                   DISPLAY          WS-String(1:62)

                   IF               WS-ConnStat NOT = -1
                                    MODIFY  hRecordset MoveNext()
                                    END-IF

                   INQUIRE          hRecordset EOF IN WS-ConnStat

           END-PERFORM.
           ACCEPT  OMITTED.
           MODIFY  hRecordset       @Close().
           MODIFY  hConnection      @Close().

       MAIN-900.   
      *Finish up.
       DESTROY hRecordset.
       DESTROY hConnection.
           GOBACK.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Adodb

Gisle,

Thanks for the example! What control should I use to generate the "def" file? I am using MSADODC.OCX, but it doesn't have a "Connection" class...

Thanks,
Rob
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Adodb

Gisle,

Ok, I figured out that I have issue with the alphabet occasionally... I need ADODB, not ADODC... Would I use something like msado15.dll?

Rob
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Adodb

Use the Microsoft ActiveX Data Objects (on the library tab), which version is really up to you, I have versions 2.0, 2.1, 2.5, 2.6, 2.7 and 2.8.
Except of 2.8 the others come from type library files (.tlb), but I suspect it is msado15.dll behind it all.

Good luck!
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Adodb

Thanks, Gisle. I'll give this a try. You've saved me a lot of time.

Rob
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Adodb

ADO is part of a package of Microsoft Data Access Components known as MDAC: http://msdn.microsoft.com/data/ref/mdac/default.aspx

Most windows PC's with IE explorer 5.5 or higher and/or MS Office 2000 or higher should have it installed already. You can also redistribute the MDAC with your application: http://www.microsoft.com/downloads/details.aspx?familyid=6C050FE3-C795-4B7D-B037-185D0506396C&displaylang=en

I could see a few uses for it at Southware. I have used it with Visual Basic, but not with Acucobol as of yet. You might eventually have compatability issues if users have different versions than what you developed with, so keep an eye out for that.


A set of ADO samples in VB is located here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmscadocodeexamplesinvisualbasic.asp
ADO Programmers Reference here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmscsection1_ado.asp
ADO Programmers Guide here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmscsection1_ado.asp


I look forwarding to seeing you at the Acucorp conference this week. 😄
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Adodb

Hello Gisle,
I tried the approach You suggested to ADO: it works fine, but how trapping errors from the activeX? When I produce an error (as "column not found" or "tabel_x doesnt' exists on database") it's always fatalk for the runtime too.
Thanks In Advance Giovanni
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Adodb

You would need to use an exception procedure to handle any errors and use C$EXCEPTINFO to determine what the error is.

CALL "C$EXCEPINFO"
USING ERROR-INFO,
ERR-SOURCE,
ERR-DESCRIPTION,
ERR-HELP-FILE,
ERR-HELP-CONTEXT,
ERR-OBJECT-HANDLE,
ERR-CONTROL-ID

Then, you can display a message or whatever other action you need to take based on the error.

Rob
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Adodb

Thanks Rob. Just to be a bit more precise; You can program a declaratives section that captures COM exceptions just like you capture file exceptions. Rob shows you how to get information about the exception.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Adodb

Hello Everyone,
I've implemented the method You both, Rob & Gisle suggested: it work fine for intercepting AdoErrores, but after I catch one of them, as for example, if I launch a

modify hConnection Execute("truncate table my_table"
, , adCmdText)
giving hRecordset

and my_table doesn't exists on the DB, then if I try to destroy hRecordset handle I always have a MAV.
(runtime is Wrun32 7.0.0)
Any Ideas?
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Adodb

I'm certainly not the expert Gisle would be on this subject, but I have had situations where I destroy an ActiveX handle and I get a MAV when the handle was never really created. So, for example, if your hRecordset handle never really gets a value, you don't need to destroy it.

I'll let Gisle confirm or deny this... 😉
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.