DB connection freezes application

DB connection freezes application

Post by Gabri » Sat, 23 Mar 2002 09:04:09



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..."
objConn.Open "DSN=...;UID=...;PWD=...;"

If objConn.State = adOpen Then
    Label1.Caption = "Connected successfully!"
End If

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!

 
 
 

DB connection freezes application

Post by dnage » Sat, 23 Mar 2002 09:14:40


Place a DoEvents before something that will freeze your
app.

But thats a little extreme in all cases...  If you place a label1.refresh
before the open call, you will see the text before the DB Open call is
made.

D.

| 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..."
| objConn.Open "DSN=...;UID=...;PWD=...;"
|
| If objConn.State = adOpen Then
|     Label1.Caption = "Connected successfully!"
| End If
|
| 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!

 
 
 

1. DB connection freezes application

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..."
objConn.Open "DSN=...;UID=...;PWD=...;"

If objConn.State = adOpen Then
    Label1.Caption = "Connected successfully!"
End If

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!

2. IPX/SPX Connection Problems

3. Oracle and MTS application DB connection issue

4. how to check how many times row selected in sql server

5. Frozen Application access SQL

6. Help! Slow SQL Server perfomance, migrated from Access

7. Application Freezes!!

8. UpdateBatch and freezing application

9. Data retrieval freezes application

10. Application freeze

11. application freezes making update

12. VFP application freezes when numeric key is used without NumLock