Connect Inventor Professionnal 2019 to MySQL8.0 Database

Connect Inventor Professionnal 2019 to MySQL8.0 Database

Anonymous
Not applicable
1,924 Views
8 Replies
Message 1 of 9

Connect Inventor Professionnal 2019 to MySQL8.0 Database

Anonymous
Not applicable

Please, i'm looking to connect Inventor Professionnal 2019 to a DATABASE in MySQL 8.0 using a VBA code.

i maked some tests in Excel and it works.

but it doesn't work using the same Code in VBA editor of Inventor.

i cheked the reference of the editor. their are the sames in Excel. So i don't know how resolve the problem.

 

this is my VBA code :

Private Sub CommandButton1_Click()
UserForm
End Sub

Private Sub UserForm()
   Dim Cn As ADODB.Connection
  Dim Server_Name As String
 Dim Database_Name As String
    Dim User_ID As String
    Dim Password As String
   Dim SQLStr As String
  Dim rs As ADODB.Recordset
 Set rs = New ADODB.Recordset
    Dim Num As String

    Server_Name = "127.0.0.1"
    Database_Name = "base"
    User_ID = "root"
    Password = "m02pas"

    Num = TextBox1.Value

    SQLStr = "SELECT numero FROM table01 WHERE numero LIKE '" & Num & "%'"

    Set Cn = New ADODB.Connection
    Cn.Open "Driver={MYSQL ODBC 8.0 Unicode Driver};Server=" & Server_Name & ";Database=" & Database_Name & ";Uid=" & User_ID & ";Pwd=" & Password & ";"
    rs.Open SQLStr, Cn, adOpenStatic

    a = rs.GetRows
    ListBox1.ColumnCount = UBound(a, 1) + 1
    ListBox1.List = Application.Transpose(a)
    rs.Close
    Set rs = Nothing
    Cn.Close
    Set Cn = Nothing
End Sub

Private Sub CommandButton2_Click()
Unload UserForm1
End Sub

Thank you.

0 Likes
Accepted solutions (1)
1,925 Views
8 Replies
Replies (8)
Message 2 of 9

Mark.Lancaster
Consultant
Consultant

@Anonymous 

 

Welcome to the Autodesk User's Community..

 

You want to be asking this over in the Inventor Customization forum https://forums.autodesk.com/t5/inventor-customization/bd-p/120

 

I will have the moderator relocate your posting there to best suit your needs.

Mark Lancaster


  &  Autodesk Services MarketPlace Provider


Autodesk Inventor Certified Professional & not an Autodesk Employee


Likes is much appreciated if the information I have shared is helpful to you and/or others


Did this resolve your issue? Please accept it "As a Solution" so others may benefit from it.

Message 3 of 9

Anonymous
Not applicable

Thank you verry much

0 Likes
Message 4 of 9

Frederick_Law
Mentor
Mentor

First, what doesn't work?

Second, you just let everyone know your username and password.

0 Likes
Message 5 of 9

Anonymous
Not applicable

It's a local DATABASE so dosn't matter if i give the password or not.

 

the VBA code that i gave, i'm using it on excel to look for the parts (Num) in the database (MySQL Server). it works...

 

now  i'm trying to use the same programme in Inventor to do the same work (to show in the  listbox1 all the number of parts which start with the value of the textbox1.value. but it doesn't work.

 

is there a configuration to make befor run the programme.

 

thanks.

 

0 Likes
Message 6 of 9

Frederick_Law
Mentor
Mentor

Add stop and watch rs and a.

See if they get value from SQL.

Message 7 of 9

Anonymous
Not applicable

Thank you for your answer.

i'm biginner too so can you tell me how to writ it in the code please.

 

Thank you in advance.

0 Likes
Message 8 of 9

BrianEkins
Mentor
Mentor

My guess is that you have a 32-bit version of Office installed and the library you're referencing to access the database is also 32-bit.  Inventor is 64-bit and uses the 64-bit version of VBA.  It's possible to install a 64-bit version of Office.  I don't know about the database library.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 9 of 9

Anonymous
Not applicable
Accepted solution

Thank you verry much for your answer.

the problem was resolved by @gmassart 

 

this is the solution :

'Déclaration de la variable de connexion
    Dim cnx As ADODB.Connection
    Dim rst As ADODB.Recordset
    Set cnx = New ADODB.Connection
    Set rst = New ADODB.Recordset
    'Définition de la chaîne de connexion
    'cnx.ConnectionString = "UID=" & NomUtilisateur & ";PWD=" & MotDePasse & ";" & "DRIVER={SQL Server};Server=" & NomServeur & ";Database=" & NomBaseDeDonnées & ";"
    cnx.ConnectionString = "Driver={SQL Server};Server=[InfoCachée];Database=[InfoCachée];Trusted_Connection=yes;"
    'Ouverture de la base de données
    cnx.Open
    'Exécution de la requête
    rst.Open [InfoCachée], cnx
    rst.Close
    Set rst = Nothing
    Set request = Nothing
    Set cnx = Nothing

thanks again for your comment

0 Likes