Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 31st, 2003, 06:13 AM
Registered User
 
Join Date: Jul 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default User feedback while ADO proc is running


I've written a small VB application that runs a SQL Server stored procedure via an ADO connection. The app is called from a Windows program. The procedure can take a minute to run, so I've increased the timeout value of the ADO connection above the default 30 seconds. I want to make users aware that the procedure is running 'in the background' and have tried adding a 'WAIT' splash screen, and changing the mouse pointer to an hourglass so that users can see that something is happening and don't start clicking frantically.

The problem is that my program appears to wait while the procedure runs. My splash screen will only display as a 'ghost screen' with a faint border, and is drawn fully once the procedure is complete. The mouse pointer briefly changes to an hourglass, but reverts to a standard pointer while the procedure runs.

Is this a common pitfall when executing database procedures with an ADO connection? How can I provide feedback to users while the stored procedure runs?


The code approximates to this currently:

Dim objADOdatasource As ADODB.Connection
Dim comADOdatasource As ADODB.Command
.....
.....

objADOdatasource.CommandTimeout > 30 seconds
comADOdatasource.CommandTimeout > 30 seconds

 With comADOdatasource
            .CommandText = cp_a_stored_procedure
            .CommandType = adCmdStoredProc 'Type : stored procedure
            .ActiveConnection = objADOdatasource.ConnectionString
 End With

display splash screen
mouse pointer = hourglass

comADOdatasource.Execute 'this is where the procedure is run

hide splash screen
mouse pointer = normal

...if return value is not success etc.


 
Old July 31st, 2003, 07:39 AM
Authorized User
 
Join Date: Jun 2003
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You may want to try inserting a Timer or the DoEvents function. Here is some info from MSDN...

DoEvents is most useful for simple things like allowing a user to cancel a process after it has started, for example a search for a file. For long-running processes, yielding the processor is better accomplished by using a Timer or delegating the task to an ActiveX EXE component.. In the latter case, the task can continue completely independent of your application, and the operating system takes case of multitasking and time slicing.

Hope this helps.

Kenny Alligood
 
Old July 31st, 2003, 09:20 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

while your program is running the executed command, is halted, so no doevents or such thing will work...
the best thing you can do, is before running the execute, show the wait window fully, doing a refresh so it viewed ok.
also you may want to put a timer on the wait window so you can run the query a second after this window appear..

HTH...

Gonzalo Bianchi
 
Old August 1st, 2003, 02:03 PM
Registered User
 
Join Date: Jul 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks guys, setting a wait timer works fine. The wait time only has to be set at 1/10 of a second for my splash screen to display fully.

This is the code now:

        frmWait.Show
        Screen.MousePointer = vbHourglass

        iStart = Timer ' Set start time.
        Do While Timer < iStart + 0.1
            DoEvents ' Yield to other processes.
        Loop

        comADOdatasource.Execute

        frmWait.Hide
        Screen.MousePointer = vbDefault

        sReturnValue = sOutputParam.Value
        .........etc.







Similar Threads
Thread Thread Starter Forum Replies Last Post
add new record to ADO recordset via stored proc tbullard Access 0 January 20th, 2006 02:35 PM
Poor performance with ADO stored proc. call aldovalerio VBScript 0 August 23rd, 2004 08:21 AM
Running DTS package from withing a stored proc flaco SQL Server DTS 2 July 27th, 2004 05:34 PM
efficiency qn:ado .AddNew VS INSERT in stored proc ak Classic ASP Databases 1 February 25th, 2004 10:08 AM
effieciency: ado .AddNew vs Insert in Stored proc ak SQL Server ASP 2 February 25th, 2004 09:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.