Every time I try to connect to a SQL Server database, using ADO, my VB
application freezes while the connection is being resolved. Once the
command is executed, the application comes back. The weird thing about
it is that it happens before (code-wise) the app reaches the line
where I'm telling it to connect to the db.
For example, say I put a label on a form in which I want to show the
status of the connection. Before connecting, it should read "Waiting
to connect to database...". In the code it would be like this:
Dim objConn as New ADODB.Connection
Label1.Caption = "Waiting to connect to database..."
If objConn.State = adOpen Then
Label1.Caption = "Connected successfully!"
When executing something like this, for some reason, the application
tries to connect before setting the label caption to the first string
(at least that is what seems to happen on the interface), freezes the
application while trying to connect, and when it does, it simply
continues with the rest of the code (in this case, sets the label
caption to the second string).
If I do a cold run, going step by step with F8, it works fine, but
when running normally it doesn't.
I've tried using DoEvents before and after the connection but it
doesn't make any difference, probably because its not inside a loop.
Is there a way to improve the performance of this code, so that it
let's the application continue running while trying to connect to a
database? Is it even possible? Thanks!