Microsoft ActiveX Data objects 2.7

tytofetytofe Member Posts: 4
I have a problem with Microsoft ActiveX Data objects 2.7 Library .I want to connect a SQL server database with automation :

Name : ADO.Connection
Type : Automation
SubType : 'Microsoft ActiveX Data Objects 2.7 Library'.Connection

I set the property 'With Events' of this automation to 'yes'.
When i start the programm, Navision execute the instruction ADO.connection.open and stop with error and close the programm !
If i set the property 'With Events' of this automation to 'no', there is no problem but i can not test if the database is correctly open or not ! (I want to test the connection and put the error in an error file).

Comments

  • DakkonDakkon Member Posts: 192
    I deffinately do NOT recommend you use the ADO objects directly from Navision. If you wish to connect to your sql db via automation from navision, I recommend you create your own activex dll in your preferred language and use the ADO components from within it. This way you can properly trap any errors and gracefully relay any problems to your navision codeunit/form/etc. I'd say that it's likely that your code is throwing an error and Navision is choking on it and crashing. Wrapper components are always a good idea when using activex objects in Navision, that were not designed to be specifically used from Navision.
    I hope this helps:)
    Thad Ryker
    I traded my sanity for a railgun :mrgreen:
  • jversusjjversusj Member Posts: 489
    anyone using WithEvents = Yes for Activex Data Objects 2.8 Library Connection?

    When i have this set to no, my code works - i can connect to an external SQL table and do some stuff with it. when i set WithEvents to Yes, however, i get an error when my code reaches the ADOConnection.Open; line of code.


    ADOConnection.ConnectionString(STRSUBSTNO(ConnectStr,Provider,"Data Source","Initial Catalog","Integrated Security"));
    ADOConnection.Open;

    I receive the following error(s):

    Microsoft Dynamics NAV
    The expression Variant cannot be type-converted to a Automation value.

    OK

    Microsoft Dynamics NAV
    This message is for C/AL programmers:

    The call to member Open failed. ADODB.Connection returned the following message:
    Operation has been cancelled by the user.

    OK

    when i start debugger, i see it throws the error sitting on the WillConnect event. i do not have any code in this trigger.
    also, i got the same error when i used ADOConnection.OPEN(connectionstring,user id,password,option) snytax instead of what is shown above.

    i wanted to try to use events to set a boolean true after Execute complete. what could i be doing wrong?
    kind of fell into this...
  • DakkonDakkon Member Posts: 192
    Firstly, I'd like to point to my prior post ;)
    The problem is most all of the event triggers from that activex object have parameters of types that have no corresponding type in Navision (hence the error message). I recommend you create your own ActiveX class in VB6 or whatever .NET language (if you prefer) and wrap the functionality you need from the ADO connection class in a Navision safe manner. For instance, you could create your own connection object inside your activex dll that then calls the ADO connection object and passes in the connection string, etc. In the same fashion, within your class you can trap the event from the ADO connection that you are interested in and fire an event of your own creation on your class object. I would rarely recommend using an activex class directly in Navision if it was not constructed with Navision in mind.
    Thad Ryker
    I traded my sanity for a railgun :mrgreen:
  • jversusjjversusj Member Posts: 489
    Dakkon wrote:
    Firstly, I'd like to point to my prior post ;)
    The problem is most all of the event triggers from that activex object have parameters of types that have no corresponding type in Navision (hence the error message). I recommend you create your own ActiveX class in VB6 or whatever .NET language (if you prefer) and wrap the functionality you need from the ADO connection class in a Navision safe manner. For instance, you could create your own connection object inside your activex dll that then calls the ADO connection object and passes in the connection string, etc. In the same fashion, within your class you can trap the event from the ADO connection that you are interested in and fire an event of your own creation on your class object. I would rarely recommend using an activex class directly in Navision if it was not constructed with Navision in mind.
    thanks dakkon, i did read your prior post but wondered if anything had changed since 2004 (new ADO library, new NAV executables...). :)

    in fact, i am now using ADO quite happily (although in a limited fashion) in NAV . i was investigating the possibility of using the events - i do not need to use them. I can find a happy alternative.
    kind of fell into this...
  • DakkonDakkon Member Posts: 192
    Unfortunately the dev side of Navision changes at a snail's pace ...actually I'd say the snail is faster. I would not hold your breath on the automation integration changing anytime soon if ever. I'm glad that it currently works for you without the events :). If you do decide to build a wrapper for the connection class I personally recommend doing it in VB6 if you can. It's much much easier to do a quick and dirty activex wrapper class in vb6 as opposed to trying to write something in .Net and expose it as an activex. I could probably throw together an example some time if you had much interest and email an archive to you of it.
    Thad Ryker
    I traded my sanity for a railgun :mrgreen:
Sign In or Register to comment.