Your answer suggested I was doing everything right except the threading. So I left that out and it worked just great.
So at least I narrowed the problem down:
My testing shows that it's not the threading with the CoTaskMemAlloc function. That works just OK.
Yet, as soon as I add SQL Threads it starts going wrong. That is: just doing %THREAD_START, 1 and stopping it works fine. But as soon as I also add a real SQL statement to execute, it goes wrong.
I'm having 2 threads. I've set the %THREAD_MAX to 20. I've used seperate DB numbers for each of the two threads (1 and 2) and used fixed statement numbers for each thread as well (4 and 5).
If I test this in a multi-user test from a webpage passing the request to the DLL, IIS crashes!
I'm using the function according to the manual (I believe) and I'm not deleting or altering any table or database (so no cach problems). It's just reading them.
The simplified code looks like this:
Code:
' DB1 and 2 are opened. The initionalize also had 'result& = SQL_Initialize(3, 256, 240, 256, 3, 1, 0, 0) 'result& = SQL_THREAD(%THREAD_MAX, 50) MainSub: ' pass info to ThreadInfo DIM ThrInf AS ThreadInfo PTR ' UDT for all necessary info in threads ThrInf = CoTaskMemAlloc(SIZEOF(@ThrInf)) IF ThrInf THEN @ThrInf.Var1 = Internal.Var1 ' UDT for local internally passed info @ThrInfo.Var2 = Session.Var2 ' UDT for local internally passed info ' for all vars @ThrInfo.SQLHit1 = 0 end if ' this example uses only 1 thread (for testing) THREAD CREATE MyThread1(ThrInf) TO hThread1 ' the thread changes the value: ThrInf.SQLHit1 and (if success: has a result stored in .recnr2) DO WHILE @ThrInf.SQLHIT1 = 0 SLEEP 1 LOOP IF @ThrInf.SQLHit1 = 3 THEN Internal.SQLHit1 = 3 Internal.recnr = @ThrInf.recnr2 ' pass result from Thread to Internal info ELSEIF @ThrInf.SQLHit1 = 4 THEN Internal.SQLHit1 = 4 END IF ' to be safe: cancel the statement SQL_STATEMENTCANCEL 1, 5 SQL_CLOSESTATEMENT 1, 5 ' close thread THREAD CLOSE hThread1 TO hResult ' free memory CoTaskMemFree ThrInf ' done Thread: FUNCTION MyThread1(ThrInf AS ThreadInfo PTR) AS LONG result& = SQL_THREAD(%THREAD_START, 1) LOCAL Thread1 AS ThreadInfo Thread1.Var1 = @ThrInf.Var1 ' etc. local SQLST as STRING, result&, StmtNr2 as double, Cols as double StmtNr2 = 5 SQLST = "Select * from Table1" result& = SQL_STATEMENT(1, StmtNr2, %IMMEDIATE, SQLST) IF (result& <> %SUCCESS AND result& <> %SUCCESS_WITH_INFO) OR SQL_ResultColumnCount(1, StmtNr2) = 0 THEN ' report action ELSE Cols = SQL_ResultColumnCount(1, StmtNr2) SQL_Fetchresult 1, StmtNr2, %FIRST_ROW ' more code to handle the results, as well as continued action / Sql statements (using the same db and stmt nr.) END IF result& = SQL_THREAD(%THREAD_STOP, 1) end function
Anybody got some ideas what I'm doing wrong?
Sincerely,
Jeroen
------------------
[This message has been edited by jeroen brouwers (edited January 22, 2001).]
Leave a comment: