I’m currently working on a small application that needs to connect to a database. I do this using the following code…
Set database_connection = New ADODB.Connection
database_connection.ConnectionString = _
"Driver={MySQL ODBC 3.51 Driver}; Server=HOST; " & _
"Database=SCHEMA; " & _
"User=USER; " & _
"Password=PASSWORD; " & _
"Option=3;"
database_connection.Open
This works fine when I run the project from the IDE, and it works file when I run the compiled exe from the command line. If I attempt to run the exe by invoking the CreateProcess function, though, it doesn’t work at all, producing the following error message…
(1) Error#: -2147467259
Desc. : Unspecified error
Source: Provider
Native Error: -2147467259
SQL State:
Help Context: 1240640
Help File:
Does anyone know what I ought to do about this? I’m working on Windows XP, and the CreateProcess call looks like…
Dim create_result As Long
Dim startup_information As STARTUPINFO
Dim our_process_information As PROCESS_INFORMATION
Dim process_attributes As SECURITY_ATTRIBUTES
Dim thread_attributes As SECURITY_ATTRIBUTES
create_result = CreateProcess(vbNullString, _
command_line, _
process_attributes, _
thread_attributes, _
0, _
0, _
0, _
vbNullString, _
startup_information, _
our_process_information)
(I suspect a permissions problem but don’t know what to do about it if it is. Nothing is appearing in the server log.)
Hmm, that coding style looks awfully familiar…
One mistake people commonly make is using the “stock”
Declaresignatures from sources such as API Viewer without understanding what they mean, e.g.:Those
As StringandAs Anydeclarations have impacts that people often ignore.Generally one is far, far better off using the “W” entrypoints and declaring all pointers as
ByVal xxx As Long, then applying the VB6 pointer functions where required. But you can lead a horse to water…Try this:
Or far, far better, try:
My guess is that this is exactly where you were “breaking” your ODBC driver (sadly an OLEDB Provider would be much better, but I don’t know of a decent free one for MySQL).
Oh, the problem (and difference here)?
You were zapping the environment block to nothing, i.e. probably breaking PATH keeps your ODBC driver from working.
Null pointers, zeros, and empty structures are entirely different things.