MySQL Connection Question

Phreak

Well-known member
Joined
Jun 7, 2002
Messages
62
Location
Iowa, United States
Ok, so I can connect to my database with the following code:

UID = txtUsername.Text
Pass = txtPass.Text
ServIP = txtHost.Text
DBName = txtDB.Text
ConPort = txtConPort.Text

conn = CreateObject("ADODB.Connection")
rs = CreateObject("ADODB.RecordSet")

conn.Open("Driver={MySQL};" & _
"Server=" & ServIP & ";" & _
"Port=" & ConPort & ";" & _
"Option=131072;" & _
"Stmt=;" & _
"Database=" & DBName & ";" & _
"Uid=" & UID & ";" & _
"Pwd=" & Pass & ";")

This is all done on an initial "Login" form, and once there is a connection detected, I want it to go away and the main form to be displayed. Is there anyway to tell when the connection is made and if so, a way to pass the connection to the main form? Or can I not use persistant connections?
 
You can declare your connection object as public in a module and then use it from there in code anywhere in your program. Just be sure to close it when you exit the app.
 
But is there a way to tell once it is connected?

Like

If conn.Open = True Then
do this stuff
EndIf


(or something like that, i know its probably not the right syntax, but i hope you get the idea)
 
Like this:

Code:
cnn is the connection object
If cnn.State = adStateOpen Then
    cnn.Close
    Set cnn = Nothing
End If

[edit]Sorry that is code I use to test whether it is open so I can close it, but you see the usage.[/edit]
 
you can use the ConnectComplete event.
but before this you have to declare your Conn object as:
dim WithEvents Conn as adodb.connection
then use the new keyword not the createobject.
 
Urgh. There are so many things wrong with that code. :)

For starters youre using ADO. Thats a no no. Secondly, youre late binding, also a no no. Thirdly, cut down on the use of "_"
s. Youll save yourself coding time.

Try ADO.NET and early binding. Search this board for a few examples.
 
Back
Top