|
-
Aug 24th, 2000, 09:45 AM
#1
Thread Starter
New Member
Hi everybody! I'm new in VB.
I want to process SQL store procedure in the SQL server and another VB functions without freezing my terminal.
When processes a SQL store procedure I can't do nothing until it ends.
How can I resolve this.
Thank you!
dinacio
-
Aug 24th, 2000, 10:30 AM
#2
Fanatic Member
I am afraid this is a little easier said than done. 
First off you will need to create an ActiveX exe project that calls the Stored procedure. And i am afraid it isn't even quite as simple as that.
You need to call a sub in the AX exe, that starts a timer, and that's it, nothing more. This means that the sub initialises a timer, and passes control back to your VB app.
When the timer event fires in your AX exe, you call the sub that calls the Stored procedure. This way, the sub is called from the AX exe, and it can run in the background, as control has already been passed back to your VB program.
Then in your sub that calls the Stored Procedure, you can raise an event back to VB after the work has been done, to let it know that it has done. You can handle this event like any normal event, e.g, click event.
I hope this has shed some light on the matter.
Iain, thats with an i by the way!
-
Aug 24th, 2000, 10:31 AM
#3
Frenzied Member
oK, I think I get what you're asking, but you've asked it in a very complicated way.
By the sound of it you have a procedure that takes a long time to run and when you run it the program freezes until it finishes.
The answer to this is a Command called DoEvents, what this does is stops the procedure briefly and lets VB handle all the other stuff it needs to do (like repanting the form, allowing the user to move it with the caption bar, letting you click buttons, etc. put the DoEvents command inside any large loops. For Example
Code:
Dim i As Integer
For i = 1 To 10000
'Process a record or something that you have to do 10000 times
Call ProcessRecor(i)
Next i
will freeze up your app until it finishes, but
Code:
Dim i As Integer
For i = 1 To 10000
'Process a record or something that you have to do 10000 times
Call ProcessRecor(i)
'Allow the App to do anything that needs doing
DoEvents
Next i
Won't freeze up your app, hope this helps.
-
Aug 24th, 2000, 12:28 PM
#4
Fanatic Member
lain17
Lain17...
That is very goooodd!!
Have u ever tried that????
I will soon
Thanks
-
Aug 24th, 2000, 02:53 PM
#5
Fanatic Member
Guys
Guys, I found and dowloaded code that does allow this kind of threading with VB
at
http://www.vbaccelerator.com/codelib/thread/exethr.htm
Don't quite understand it yet!!
Please take a look and if you do understand it...
share with us...
I am currently looking at it..
Thanks
-
Aug 24th, 2000, 04:33 PM
#6
Fanatic Member
ok..me again
Interesting...
Usually when I invoke the stored proc...
until it's completed running... My screen turns unreadable
and locked
I just tried sending this
ls_sqlString = "select count(*) from tblportTable"
Set rs_me = ExecuteInLineSql(ls_sqlString, m_objConn)
where m_objConn is an active ADO connection
rs_me is and ADODB.recordset
and ExecuteInLineSql is as follows
Public Function ExecuteInLineSql(ArgString As String, ByRef ArgConnObj As ADODB.Connection) As ADODB.Recordset
Dim m_objCmd As New ADODB.Command
Dim rs As New ADODB.Recordset
On Error GoTo ExecuteInLineSql_EH
'Set Command Object Properties
With m_objCmd
.ActiveConnection = ArgConnObj
.CommandText = ArgString
.CommandType = adCmdText
Set rs = .Execute(, , adAsyncFetchNonBlocking)
DoEvents
End With
'De-ference the Command Object
Set m_objCmd = Nothing
Set ExecuteInLineSql = rs
Set rs = Nothing
Exit Function
ExecuteInLineSql_EH:
Set ExecuteInLineSql = Nothing
End Function
Note: the option "adAsyncFetchNonBlocking" with the .execute
somehow allows me to see everything on the screen
and apparently it looks like I am not locked?
Could someone confirm or deny?
-
Aug 25th, 2000, 02:18 AM
#7
Hyperactive Member
Dan Appleman has written a very intresting article about threading in VB:
http://www.desaware.com/articles/threadingL3.htm
if the link doesn't work, it's in the technical articles section, "A Thread To Visual Basic"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|