borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (COMM PORT Problem)Next Topic (DataGrid and Font adjustments) New Topic New Poll Post Reply
AndreaVB Forum : VB.Net : VB.NET: Adodb Recordsets in a thread
Poster Message
cgibb
Level: Guest


icon VB.NET: Adodb Recordsets in a thread  Archived to Disk

I am writing a component that will get datafrom a number of different sources and then complile it into to recordset, and return it to the calling application.
Currently, the application that is doing this was written in delphi, as it supported multi-threading, but as only one person in the office knows delphi, and the application is extremely inefficient as it is doing explicit type conversions for every field of every record.
I created a test app, the the method to get the data runs if I just called in from the Main() subroutine, but as soon as I call it in a thread, I get the following error message:

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in MultiDBNET.exe

Additional information: Non-NULL controlling IUnknown was specified, and either the requested interface was not
IUnknown, or the provider does not support COM aggregation.

Does anyone know why this is not running in a thread?
I have attached the code if you want to have a look at it.

Thanks very much in advance!!!



----------START OF CODE--------
Imports System.Threading
Imports System.Data
Imports System.Data.OleDb


Module MultiDBNET
    Sub Main()
        Dim ConnectionString
        Dim QueryText
        Dim objQuery As QueryDatabase
        Dim objThread As Thread

        ConnectionString = "provider=FnDBProvider;data source=DefaultIMS:DevImage:FileNet;user id=SysAdmin;password=SysAdmin;Prompt=" & ADODB.ConnectPromptEnum.adPromptNever & ";SystemType=" & idmSysTypeOptions.idmSysTypeIS & ";"
        QueryText = "SELECT * from FnDocument Where F_DOCCLASSNAME = 'CCELAAP'"

        objQuery = New QueryDatabase()
        objQuery.ConnectionString = ConnectionString
        objQuery.Query = QueryText

        'objQuery.RunQuery() --> using this line instead of the threading commands below works fine!

        objThread = New Thread(AddressOf objQuery.RunQuery)
        objThread.Start()
        objThread.Join()
    End Sub
End Module


Public Class QueryDatabase
    'This is used to actually execute the query.  This is the one that will be run multithreaded.
    Public Query As String
    Public ConnectionString As String
    Dim cnQuery As ADODB.Connection
    Dim rsResults As ADODB.Recordset

    Public Sub RunQuery()
        cnQuery = New ADODB.Connection()
        cnQuery.ConnectionString = ConnectionString
        cnQuery.Open(ConnectionString, "", "", -1)
        rsResults = cnQuery.Execute("Select * from FnDocument Where F_DOCCLASSNAME='CCELAAP'")
        MsgBox(rsResults.RecordCount & "Results Returned")
        Exit Sub
    End Sub
End Class





[Edited by admin on 03-05-2002 at 04:07 PM GMT]

03-05-2002 at 02:26 PM
| Quote Reply
lorenzo.gardoni
Level: Trainee

Registered: 25-07-2006
Posts: 2
icon Re: VB.NET: Adodb Recordsets in a thread

I have the same problem, have you a solution?

25-07-2006 at 04:14 PM
View Profile Send Email to User Show All Posts | Quote Reply
lorenzo.gardoni
Level: Trainee

Registered: 25-07-2006
Posts: 2
icon Re: VB.NET: Adodb Recordsets in a thread

  

Add the bold line code:
objThread = New Thread(AddressOf objQuery.RunQuery)
objThread.SetApartmentState(ApartmentState.STA)
objThread.Start()

26-07-2006 at 03:37 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB.Net : VB.NET: Adodb Recordsets in a thread
Previous Topic (COMM PORT Problem)Next Topic (DataGrid and Font adjustments) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder