Solved

Multiple connections to access DB

Posted on 2004-09-22
4
164 Views
Last Modified: 2010-04-23
I will post some code here.
I am creating multi threads to help my process go along faster.

When I am filling one of my datagrid i am getting an error stating:connection open and executing

I feel that this error is because it is creating another connection to the database.

How does one allow multiple connections to the same access database at the same time.  The connections are only  SELECT queries no update, delete, or adds.

This is going to be on a server with muliple users connecting



    Public Sub frm_search_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'hide the child button
        hide_child()
        'hide the parent button
        hide_parent()
        'hide the gif
        hideimage()
        'check online
        Online_Offline()


        ' On page load add databinding for the spins desc
        Me.spins_txt.DataBindings.Add("text", Me.DbDataSet.Tables(0), "DESC")

        ' lets hide columns from view in our DataSet
        Me.DataGrid.TableStyles(0).GridColumnStyles("DESC").Width = 0
        'Me.DataGrid.TableStyles(0).GridColumnStyles("Image").Width = 0
        Me.DataGrid.TableStyles(0).GridColumnStyles("Part_Num").Width = 10


        If online = True Then
            online_txt.Text = "ONLINE"
        Else
            online_txt.Text = "OFFLINE"

        End If

        Fill_Child_dataview()
    End Sub



 Public Sub Fill_Child_dataview()
        Dim workthread2 As New System.Threading.Thread(AddressOf fillchilddata)
        workthread2.Start()
    End Sub

    Private Sub fillchilddata()
        'Application.DoEvents()
        Me.OleDbDataAdapter2.Fill(Me.Childdataset)
            End Sub





Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not filterStr.Equals(String.Empty) Then

            If Not (search_txt.Text.Equals(String.Empty)) Then
                cmdText &= " AND T_PARTS.PRODUCT_CODE IN (" & filterStr & ")"
            Else
                cmdText &= " WHERE T_PARTS.PRODUCT_CODE IN (" & filterStr & ")"
            End If
        End If

        ' Set the SelectCommand to the newly constructed query
        Me.OleDbSelectCommand1.CommandText = cmdText
        'Execute the query
        ' create multi thread
        StartDoWork()
    End Sub


  Private Sub StartDoWork()
        Dim workThread As New System.Threading.Thread(AddressOf DoWork)
        workThread.Start()
    End Sub

    Private Sub DoWork()

        showimage()

        DbDataSet.Clear()
        Application.DoEvents()
        Me.OleDbDataAdapter1.Fill(Me.DbDataSet)            <====================This is where the error happens
        '// Do your work here
        hideimage()

    End Sub



Public Sub Start_PRNT_CHLD()
        Dim workthread1 As New System.Threading.Thread(AddressOf Do_PRNT_CHLD)
        workthread1.Start()
    End Sub

    Private Sub Do_PRNT_CHLD()
        Application.DoEvents()
       ' look_for_parent()
        look_for_child()
    End Sub



 Public Sub look_for_child()

        Dim drv1 As DataRowView 'Data Row View object to query DataView object

        'Associate the dataview
        Dim dataview1 As New DataView
        dataview1.Table = Me.Childdataset.Tables("T_PRNT_CHLD")

        'Apply a filter against any of the columns in View...
        ' dataview.RowFilter = "[CHLD] Like '" & pnmain & "'"

        For Each drv1 In dataview1
            _pnmain1 = CStr(drv1("PRNT"))

            If _pnmain1 = pnmain Then
                show_child()
                Exit For
            Else
                hide_child()
            End If
        Next
    End Sub
0
Comment
Question by:malanois
  • 2
  • 2
4 Comments
 
LVL 34

Accepted Solution

by:
flavo earned 500 total points
Comment Utility
Is it because both your OleDbDataAdapter1 and OleDbSelectCommand1 are using the same connection...
0
 

Author Comment

by:malanois
Comment Utility
hmmmm......

I will try a different connection and let you know.
0
 

Author Comment

by:malanois
Comment Utility
that was it thanks
0
 
LVL 34

Expert Comment

by:flavo
Comment Utility
Cheers mate.

Glad its working now!

Dave
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now