DB connection freezes application 
Author Message
 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!



Tue, 07 Sep 2004 08:04:09 GMT  
 DB connection freezes application
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!



Tue, 07 Sep 2004 08:14:40 GMT  
 DB connection freezes application
Hi,

I think code works fine, it just does not have  time to
redraw label's caption. Try to add DoEvents

DoEvents
Label1.Caption = "Waiting to connect to database..."
objConn.Open "DSN=...;UID=...;PWD=...;"

Val

Quote:
>-----Original Message-----
>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!
>.



Tue, 07 Sep 2004 22:04:05 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. DB connection freezes application

2. Oracle and MTS application DB connection issue

3. VB freezing up on DB transactions

4. OLE DB Jet 4 Provider FREEZES???

5. OLE DB Jet 4 FREEZES???

6. https connection using WinInet API in VB5.0 freezes on exit

7. Global DB Connections...RunTime Variable used for Design-Time DataAdapter Connection

8. Visual Studio .NET freezes when trying to run an application

9. Application freezes one user

10. Help: Avoid application freezes when menu is selected

11. COM+ application freezing

12. MScomm freeze the main application

 

 
Powered by phpBB® Forum Software