473,659 Members | 2,640 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OleDbConnection and MultiThreading

Hello!

My Application is Multi-Threaded, where i have several threads which get
datas and write them to the database, or have to read from the database
to compare the datas and make updates if needed.

The Database is MS Access.

Connection String:

Provider=Micros oft.Jet.OLEDB.4 .0;Data Source=database .mdb

I open the connection in the main routine

private OleDbConnection OleConn;
public OleDbConnection _strDatabase
{
get
{
if (OleConn == null)
{
try
{
OleConn = new OleDbConnection (strConnstring) ;
OleConn.Open();
}
}
return (OleConn);
}
}

Then i have a own dll where i have the write and read function included
and call it with "using" statement, the own writen dispose members don't
close the connection to the database (or did dispose do this automatic?)

Everything runs fine, but when i have 3 or more Threads running on the
same time i get sometimes the ole exception "ExecuteRea der needs an open
and usable Connection. Current Connectionstatu s: Open, Executing" and
the routine will get no datas back.

I included lock(this) into everything which calls up routines to read or
write to the database, only have lock(this) arround the read and write
function had no luck and produces much more errors like the above one.

I can do a workaround by opening the connection everytime i have a read
or write access. That works fine (no errors at all, even with large
amount of Threads), but i needs much more time to do all the database
stuff.

Any Help would be great


Regards


Matthias
Nov 16 '05 #1
1 6919
"=?Utf-8?B?U2F1cmFiaCB OYW5kdQ==?="
<Sa**********@d iscussions.micr osoft.com> wrote in
news:D9******** *************** ***********@mic rosoft.com:
The call to Dispose will automatically close the connection. Also
there is a limitation in the current version of ADO.NET that you can
have only 1 open DataReader per connection object.


Hi Saurabh,

thanks for your answer, but i found the problem. I thought i had delete
the Post out of the newsgroup.

The dispose won't close the Connection, because it's defined at the Main
Program. The Problem was, that i did

lock(this)

which seems not to work, then i tried

lock(Conn) // Where Conn is the Connection created at Main Program

and it works fine now. Had only to lock the database access parts of the
two subroutines which do the job for me. Now i can access from
everypoint of the application to the dll-routine, where i give over Conn
in the constructor and have no more errors..

The weird point is, that at every Example about Thread Safety you see
lock(this) or Monitor.Enter(t his), but that won't work here.


Thanks you

Matthias
Nov 16 '05 #2

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

Similar topics

47
3722
by: mihai | last post by:
What does the standard say about those two? Is any assurance that the use of STL is thread safe? Have a nice day, Mihai.
1
7226
by: Lilly | last post by:
Hi all. I'm really sorry for this post, I'm sure most of you will think it's a silly question, but the following doesn't work and I'm really new to ASP.NET: <%@ Page Language="C#" %> <%@ import Namespace="System.Data" %> <%@ import Namespace="System.Data.OleDb" %> <script runat="server">
16
8493
by: Robert Zurer | last post by:
Can anyone suggest the best book or part of a book on this subject. I'm looking for an in-depth treatment with examples in C# TIA Robert Zurer robert@zurer.com
5
2133
by: sarge | last post by:
I would like to know how to perform simple multithreading. I had created a simple form to test out if I was multithreading properly, but got buggy results. Sometime the whole thig would lock up when I got two threads going at the same time. What I have is two text boxes (textBox1 and textBox2) and four buttons(cmdStartThread1, cmdStartThread2, cmdStopThread1, cmdStopThread2)
9
2455
by: tommy | last post by:
hi, i have found a example for multithreading and asp.net http://www.fawcette.com/vsm/2002_11/magazine/features/chester/ i want to speed up my website ... if my website is starting, they should build a database-connection and send a few sqls
2
2307
by: Rich | last post by:
Hello, I have set up a multithreading routine in a Test VB.net proj, and it appears to be working OK in debug mode and I am not using synchronization. Multithreading is a new thing for me, and I just wanted to ask if I am missing anything based on the following scenario. My test app pulls data from a large external data source which has a table-like structure (but not rdbms - more
55
3299
by: Sam | last post by:
Hi, I have a serious issue using multithreading. A sample application showing my issue can be downloaded here: http://graphicsxp.free.fr/WindowsApplication11.zip The problem is that I need to call operations on Controls from a delegate, otherwise it does not work. However each time I've done an operation, I must update the progressbar and progresslabel, but this cannot be done in the delegate as it does not work.
5
2483
by: sandy82 | last post by:
Whats actuallly multithreading is ... and how threading and multithreading differ . Can any1 guide how multithreading is used on the Web .. i mean a practical scenario in which u use multithreading online using C# .
7
16301
by: Ray | last post by:
Hello, Greetings! I'm looking for a solid C++ multithreading book. Can you recommend one? I don't think I've seen a multithreading C++ book that everybody thinks is good (like Effective C++ or Exceptional C++, for example). Platform-specific (e.g.: Win32, POSIX) is OK, as long as it's good :) Thank you, Ray
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8339
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8751
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8629
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2757
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.