|
-
April 25th, 2011, 03:12 PM
#1
MySQL connection through a DLL
Hello
I was using Excel-VBA to connect to a MySQL database with ADO in this way:
Dim conn As ADODB.Connection
conn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" & _
"SERVER=" & myServer & ";" & _
"DATABASE=" & myDatabase & ";" & _
"UID=" & myDBuser & ";PWD=" & myDBpwd & "; OPTION=3"
conn.Open
But I wanted more privacy removing that code from Excel (and the definition of connection constants). My idea was to create a DLL (myconn.dll) with a class called MySQL.cls with this code:
Function DBConnect() As ADODB.Connection
Dim conn As ADODB.Connection
Set conn = New ADODB.Connection
conn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" & _
"SERVER=" & myServer & ";" & _
"DATABASE=" & myDatabase & ";" & _
"UID=" & myDBuser & ";PWD=" & myDBpwd & "; OPTION=3"
conn.Open
Set DBConnect = conn
End Function
From Excel, I reference myconn.dll (that is located at system32 and registered) and I use this code:
Dim conn As ADODB.Connection
Set procMy = New myconn.MySQL
Set conn = procMy.DBConnect
However, this code does not compile: it shows the error "Compile Error: Object Library Invalid or Contains References to Object Definitions that could not be found" and it marks the word DBConnect in my last line code.
Anybody has any idea about this error? I was already wearching in the web without success. What it should be the best strategy to store my constants for database connection in a safe place?
Juan C.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|