Phreak Posted September 26, 2002 Posted September 26, 2002 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? Quote If it works... don't worry, I'll fix it.
dcl3500 Posted September 26, 2002 Posted September 26, 2002 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. Quote 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.
Phreak Posted September 26, 2002 Author Posted September 26, 2002 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) Quote If it works... don't worry, I'll fix it.
dcl3500 Posted September 26, 2002 Posted September 26, 2002 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] Quote 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.
Guest emad Posted September 26, 2002 Posted September 26, 2002 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. Quote
Phreak Posted September 27, 2002 Author Posted September 27, 2002 I'm using .NET... does that matter? Because it seems to not like any of the suggestions you guys are given me..... Quote If it works... don't worry, I'll fix it.
dcl3500 Posted September 27, 2002 Posted September 27, 2002 Yeah the .net makes a bit of a difference. Haven't tinkered much with .net yet.... Quote 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* Derek Stone Posted September 27, 2002 *Gurus* Posted September 27, 2002 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. Quote Posting Guidelines
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.