Solved

Multiple connections to access DB

Posted on 2004-09-22
4
166 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Vb. Net application freezes 9 45
VB.Net - Windows UserName index and length error 4 29
Crystal reports vb.net 2 39
VB.Net - TypeInitializer Error 25 25
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

815 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

13 Experts available now in Live!

Get 1:1 Help Now