Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to implement a progress bar while running a remote v
Message
From
21/05/2021 15:57:12
 
 
To
20/05/2021 12:55:14
Walter Meester
HoogkarspelNetherlands
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
01680151
Message ID:
01680671
Views:
51
>>>>>>>>So, how can I get the SQL Server session id my query is running in?
>>>>>>>
>>>>>>>SELECT @@SPID
>>>>>>
>>>>>>Thank you.
>>>>>>
>>>>>>So, you say the query that runs the lengthy query should have an asynchronous connection, and the one that reads the advance of the first query should not be asynchronous. What I don get is, in what moment the one that reads the advance should be issued? And how can I know that the lengthy query is completed?
>>>>>
>>>>>Yes,.... and you can run the query that read the advance whenever (e.g. timer) you want to update the user on its progress
>>>>>
>>>>>You know when the query is completed when SQLEXEC(nASyncHandle) returns any other values than 0
>>>>>
>>>>>Walter,
>>>>
>>>>So, I guess I should do something like this:
>>>>
>>>>lnConn= SQLCONNECT('myOdbcDsn', 'myUserId', 'myPassword')
>>>>SQLSETPROP(lnConn, 'Asynchronous', .T.)
>>>>DO WHILE SQLEXEC(lnConn, 'SELECT * FROM myOrders', 'myCursor') = 0
>>>>   ** Show user something...
>>>>   ** Update progressbar...
>>>>ENDDO
>>>>** Continue program flow.
>>>>
>>>>
>>>>If my example is correct, how can I know whether the long query terminated fine (returned 1) or not (returned -1) after the DO...WHILE loop?.
>>>>
>>>>TIA.
>>>
>>>Yes, that would be ok. I'd build some delay (like a Sleep API call) of 100 ms in there.
>>
>>Thanks Walter. But what is still not clear to me, is when to use SQLEXEC(lnConn), in other wrods, when / where to use SQLEXEC () without the "SELECT" command.
>>
>
>Ok, the following is untested, but I guess the following would work
>
>
>nhandle1 = SQLSTRINGCONNECT(cConnectionString)
>nhandle2 = SQLSTRINGCONNECT(cConnectionString)
>
>SQLSETPROP(nHandle1,"Asynchronous", .T.)
>
>** Get the SPID you need for determining the progress
>SQLEXEC(nHandle2, "SELECT @@SPID as spid","X")
>nSPID = X.SPID
>
>** Execute the main query, asynchronously
>SQLEXEC(nHandle1, "SELECT * FROM Orders", "Orders")
>
>** Wait for it to complete
>DO WHILE SQLEXEC(nHandle1) = 0
>
>	** Query still runs, get the progress
>	SQLEXEC(nHandle2, "SELECT percent_complete FROM sys.dm_exec_requests WHERE session_id=?nSPID", "Y")
>	nPercent = y.percent_complete
>
>	**Update progress bar
>	DO updateProgressbar WITH nPercent
>	
>	** Sleep 100 ms
>	Sleep(100)
>ENDDO
>
>SELECT Orders
>....
>
>
>Walter,

Now it's vrey clear. Thank you Walter.
Previous
Reply
Map
View

Click here to load this message in the networking platform