COMException including Excel during ADO connection

0

Ok, i don't know if it will be useful but i want to share. Modos and admin will delete if they want.

I'm developping a VB application (actually, i migrate one from Excel VBA) to interact with MySQL Database. I use VS 2019 16.8.2, Windows 7 x64.

I got a cryptic issue during connection to the database (using ADO, reference used: MS ADO 2.6). Here's the code:

    Public Sub test_connect()

            Dim server_name As String
            Dim database_name As String
            Dim login_database As String
            Dim port_number As String
            Dim pwd_database As String
    
            server_name = "my_server"
            database_name = "my_database"
            login_database = "whoisyourdaddy"
            pwd_database = "youare"
    
            connexion_dlweb_doc = New ADODB.Connection With {
                .ConnectionString = "DRIVER={MySQL ODBC 8.0 ANSI Driver};" _
            & "SERVER=" & server_name & "; " _
            & "PORT=" & port_number & "; " _
            & "DATABASE=" & database_name & "; " _
            & "UID=" & login_database & "; " _
            & "PWD=" & pwd_database & "; " _
            & "OPTION=3"
            }
 
            If connexion_dlweb_doc.State <> adStateOpen Then
                connexion_dlweb_doc.Open()
            End If
        End Sub

So, i got an exception with the " connexion_dlweb_doc = New ADODB.Connection" command. It's where it becomes cryptic: System.TypeInitializationException : 'The type initializer for 'MyAPP.mod_declaration_variables' threw an exception.' COMException : Retrieving the COM class factory for component with CLSID {00020819-0000-0000-C000-000000000046} failed due to the following error: 80040154 Classe non enregistrée (0x80040154 (REGDB_E_CLASSNOTREG)).

mod_declaration_variables is a module where i declare global variables like connexion_dlweb_doc:

Public connexion_dlweb_doc As ADODB.Connection

So, i asked my best friend google about this cryptic message and the CLSID {00020819-0000-0000-C000-000000000046} refer to...Microsoft.Interop.Excel 14.0.0.0 I use the reference MS Excel Objet Library 14.0 in my project. How did this interact with the ADO connection part? What's the link? Why the code crash here and not before? I don't know why but the solution was to delete (or comment) every variable declaration using Excel library, e.g: Public xlApp_arbo_wiki As Excel.Application

Guess it would help noobs like me.

mysql
excel
vb.net
visual-studio
ado
asked on Stack Overflow Dec 4, 2020 by 8oris

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0