Solved

Multiple connections to access DB

Posted on 2004-09-22
4
169 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

624 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