473,395 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Threading and Database connection problems

I have multiple threads in my application, each which open a connection to a
database as follows:

Sub ReaderThread()

Dim cmd As New OleDbCommand
Dim dr As OleDbDataReader
cmd.Connection = cn
cmd.CommandText = "SELECT * from Mytable"
dr = cmd.ExecuteReader

While dr.Read

'Do something

End While

cmd.dispose()
dr.close

do
'Do lots of things
loop

end sub
I am getting an error saying that "There is already a connection open" which
suggests that a connection on one thread is fighting with a connection on
the other.

Since I am declaring dr and cmd locally I can't work out why I am getting
this error.

-Jerry
Nov 21 '05 #1
4 1049
Jerry,

In Net 1.x you can only use one connection in a time.

So when you want to use it as you do, you should create everytime a new
connection.

What is better anyway to get a more efficient connection.pooling (and than
use dispose in this case to close it everytime when your datareader process
is ready)

I hope this helps?

Cor

"Jerry Spence1" <je**********@somewhere.com>
I have multiple threads in my application, each which open a connection to
a
database as follows:

Sub ReaderThread()

Dim cmd As New OleDbCommand
Dim dr As OleDbDataReader
cmd.Connection = cn
cmd.CommandText = "SELECT * from Mytable"
dr = cmd.ExecuteReader

While dr.Read

'Do something

End While

cmd.dispose()
dr.close

do
'Do lots of things
loop

end sub
I am getting an error saying that "There is already a connection open"
which
suggests that a connection on one thread is fighting with a connection on
the other.

Since I am declaring dr and cmd locally I can't work out why I am getting
this error.

-Jerry

Nov 21 '05 #2
"Jerry Spence1" <je**********@somewhere.com> schrieb:
I have multiple threads in my application, each which open a connection to
a
database as follows:
[...]
I am getting an error saying that "There is already a connection open"
which
suggests that a connection on one thread is fighting with a connection on
the other.


<URL:http://www.google.de/groups?threadm=%23xyXF%24xwDHA.2712%40tk2msftngp13 .phx.gbl>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3
Herfried,

When you want to show a thread about this than it is in my opinion better to
use a thread with Angel Saenz-Badillos[MS] in it.

Cor
Nov 21 '05 #4
Thank you all very much. Yes - I had the connection itself as a Public
variable. I have redefined it in each thread and it works fine.

Cheers

-Jerry

"Cor Ligthert" <no************@planet.nl> wrote in message
news:ec**************@TK2MSFTNGP14.phx.gbl...
Herfried,

When you want to show a thread about this than it is in my opinion better to use a thread with Angel Saenz-Badillos[MS] in it.

Cor

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mudge | last post by:
Hi, My hosting provider only allows me to use 50 connections to my MySQL database that my Web site will use. I don't know what this 50 connections means exactly. Does this mean that only 50...
15
by: Phil | last post by:
Hi, I've a simple asp.net page with one button. In the OnClick event, I want to create a thread that will perform a long runninf task. Here is a sample code in the OnClick Thread t = new...
18
by: Frank Rizzo | last post by:
Hello, I have a class with all static methods that is called by multiple threads. I was wondering what effect that has on the competing threads. Does Thread2 have to wait until Thread1 is done...
0
by: Mike Caputo | last post by:
I'm connecting to a DB on a dual-processor 2.8 Ghz server with 2.5 gig RAM. So I've got plenty of muscle, and I'd like to do double-time on one update command. The command calls a stored procedure...
0
by: richard | last post by:
OS: Winxp and Win2003 Visual Basic.NET 2003 MS-SQL Server 2000 hey all I am a newbie in vb.net but i have managed to build a simple chat server in vb.net using socket and a client connecting...
10
by: jt | last post by:
The program works like this: There is a form with a button. When the form is loaded, a separate thread is started which is retreiving/updating data in the database every x seconds. When clicked...
7
by: Mike P | last post by:
I am trying to write my first program using threading..basically I am moving messages from an Outlook inbox and want to show the user where the process is up to without having to wait until it has...
1
by: Robert.R.Emmel | last post by:
Hello, I am using the threading module and the Queue module in python to to send out shipment tracking URL requests. Is there a way to timeout a thread within a Queue? I think the way I...
1
by: Pradip | last post by:
Hello every body. I am new to this forum and also in Python. Read many things about multi threading in python. But still having problem. I am using Django Framework with Python having PostgreSQL...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.