Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

If it works... don't worry, I'll fix it.
Posted
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.

Don

 

"When you're in jail, a good friend will be trying to bail you out. A BEST friend will be in the cell next to you saying, 'Damn, that was fun.'" - Anon.

Posted

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 it's probably not the right syntax, but i hope you get the idea)

If it works... don't worry, I'll fix it.
Posted

Like this:

 

'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]

Don

 

"When you're in jail, a good friend will be trying to bail you out. A BEST friend will be in the cell next to you saying, 'Damn, that was fun.'" - Anon.

Posted

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.

Posted
I'm using .NET... does that matter? Because it seems to not like any of the suggestions you guys are given me.....
If it works... don't worry, I'll fix it.
Posted
Yeah the .net makes a bit of a difference. Haven't tinkered much with .net yet....

Don

 

"When you're in jail, a good friend will be trying to bail you out. A BEST friend will be in the cell next to you saying, 'Damn, that was fun.'" - Anon.

  • *Gurus*
Posted

Urgh. There are so many things wrong with that code. :)

 

For starters you're using ADO. That's a no no. Secondly, you're late binding, also a no no. Thirdly, cut down on the use of "_"

s. You'll save yourself coding time.

 

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...