Solved

Multiple connections to access DB

Posted on 2004-09-22
4
167 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
ID: 12127814
Is it because both your OleDbDataAdapter1 and OleDbSelectCommand1 are using the same connection...
0
 

Author Comment

by:malanois
ID: 12132365
hmmmm......

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

Author Comment

by:malanois
ID: 12142813
that was it thanks
0
 
LVL 34

Expert Comment

by:flavo
ID: 12148282
Cheers mate.

Glad its working now!

Dave
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

820 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