adodb late binding error

Abdelmalek Aitouche 176 Reputation points
2020-10-27T13:08:27.973+00:00

@Castorix31
Sorry to bother again.
This time I am getting a Null parameter error message when I try to instanciate a connection, a command and a recordset with adodb.dll
I guess its still a problem a parameters that I still don't master.
I have no documentation related to the topic and I could not find any useful on the internet.

Could you please teach me the tricks how to know which parameter I need for these cases. Once I understand the logic behind, I will be better positioned to tackle the problems.

Thank you in advance.
I have included the code below for you to know what I need to do.

Dim assemblyName As String = Application.StartupPath & "\Dependencies\adodb.dll"
Dim assy As Assembly = Assembly.LoadFrom(assemblyName)
Dim Types() As Type = assy.GetTypes()
Dim adodbConnection As Type = assy.GetType("adodb.Connection")
Dim adodbRecordset As Type = assy.GetType("adodb.Recordset")
Dim adodbCommand As Type = assy.GetType("adodb.Command")

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,031 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 84,286 Reputation points
    2020-10-27T13:39:03.79+00:00

    Check what is inside Types()
    On my version, adodb is in uppercase : ADODB
    This test works for me =>

    Dim assemblyName As String = Application.StartupPath & "\Dependencies\adodb.dll"
    Dim assy As Assembly = Assembly.LoadFrom(assemblyName)
    Dim Types() As Type = assy.GetTypes()
    Dim adodbConnection As Type = assy.GetType("ADODB.ConnectionClass")
    Dim adodbRecordset As Type = assy.GetType("ADODB.Recordset")
    Dim adodbCommand As Type = assy.GetType("ADODB.Command")
    
    Dim connectString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" &
    Application.StartupPath & "\App_Data\Employees.mdb"
    'Application.StartupPath & "\App_Data\OmnitechDB.mdb"
    Dim objConnection As Object = Activator.CreateInstance(adodbConnection)
    'Dim objConnectString As PropertyInfo = adodbConnection.GetProperty("ADODB.ConnectionString")
    Dim openDataBase As MethodInfo = adodbConnection.GetMethod("Open")
    ' FullName = "ADODB.ConnectionClass.Open(System.String, System.String, System.String, Int32)"
    Dim parametersArray() As Object = New Object() {connectString, Nothing, Nothing, Nothing}
    openDataBase.Invoke(objConnection, parametersArray)
    

    But it is simpler to add the reference "Microsoft ActiveX Data Objects 6.1 library"
    then,

                Dim conn As ADODB.Connection = New ADODB.Connection()
                Dim connectString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" &
                Application.StartupPath & "\App_Data\Employees.mdb"
                conn.Open(connectString)
                ' code...
                conn.Close()
    
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Abdelmalek Aitouche 176 Reputation points
    2020-10-27T17:28:30.88+00:00

    Thanks a lot for your prompt reply and valuable help.
    Now the connection is established with the database.

    You're right. I am using early binding in my projects. The thing is that sometimes, there are portability issues on other computers when the application is run on another host which throws runtime errors due to activex not properly registered. I have been experiencing this issue for a long time using several installers.

    That's why I have opted for this backup method, which is by the way harder but at least the link is ensured to use the types, properties and methods available.

    Best regards,
    Abdelmalek Aitouche

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.