[#1000338] Bug using C# OLEDB connection and threads

View Trackers | Bugs | Download .csv | Monitor

2005-06-21 16:43
Submitted by:
Jean-Philippe JACOUPY (zeth)
Assigned to:
Nobody (None)
Bug using C# OLEDB connection and threads

Detailed description
Here's my problem.

I'm running a PostgreSQL v8.0 with PgOleDb v1.0.0.19 under Windows. I want to connect to it in a thread using C# OleDB connection. I can create my connection but whenever I try to execute a simple query "SELECT MAX(id) FROM table;"

When I run the data reader, I obtain an exception as follow: E_NOINTERFACE.

The problem only occur in a Thread and only with a SELECT query (with an insert it works).

When I run the query in the main thread, and not in it's own thread, it works.

My connection string:

"Provider=PostgreSQL;Data Source=localhost;location=EXOS;User ID=nyu;password=nyu"

Here is my sample code I use to execute my query:

System.Data.OleDb.OleDbDataReader aReader;
aReader = myCommand.ExecuteReader();

while(aReader.Read() )
sWork = aReader.GetInt32(0).ToString();

I have attached the traces (level 3 trace log) of PgOleDb of the problem in a thread.

- Exception from .NET:
'System.Data.OleDb.OleDbException': E_NOINTERFACE(0x80004002).

- Stack Trace:!System.Data.OleDb.OleDbDataReader::ProcessResults(__int32 hr = -2147467262) + 0x5a octets!System.Data.OleDb.OleDbDataReader::NextResult() + 0x131 octets!System.Data.OleDb.OleDbCommand::ExecuteReaderInternal(System.Data.CommandBehavior behavior = Default, String* method = "ExecuteReader") + 0x14c octets!System.Data.OleDb.OleDbCommand::ExecuteReader(System.Data.CommandBehavior behavior = Default) + 0x35 octets!System.Data.OleDb.OleDbCommand::ExecuteReader() + 0x12 octets


Date: 2012-03-07 17:17
Sender: tomi crow

you can see in different ways to connect database from following link

Date: 2006-04-29 11:59
Sender: Sławomir Wojtasiak

ODBC works fine, but I had some problems using it with C# (version This version sometimes creshed without concrete reason. One of my friends told me that it has been fixed in new versions of driver, but I didn't test them. In future I plan to use Npgsql - .Net Data Provider.
Date: 2005-12-01 13:03
Sender: Jean-Philippe JACOUPY

Well It is a bit more complicated since I'm in a real time
environnement I can't use dynamic connections.

I've found a work around with static connection but I had to
pass my connection instance to any function whitch needed
the connection (even if she is static). This was kinda odd,
so I went with the ODBC drivers.

I need to try one last thing for OleDB drivers Ill post back
the results.

JACOUPY Jean-Philippe
Date: 2005-09-17 20:59
Sender: Sławomir Wojtasiak

The error that you describe in your first post, you can resolve by adding Application.OleRequired() in your thread. I didn't try static connections, but when I use dynamic all work fine with select-like query and any other. Maybe problem is due to open connection by other thread.

/// <summary>
/// New therad.
/// </summary>
public void GeneratorThread() {

IDbConnection connection = m_DatabaseCtrl.Connection;

IDataReader reader = null;

try {


IDbCommand command = connection.CreateCommand();
String query = String.Format("SELECT MAX(\"Value\") FROM \"Table\"");

command.CommandText = query;
reader = command.ExecuteReader(CommandBehavior.SingleRow);

if(reader.Read()) {
int val = reader.GetInt32(0);

This code work without any arrors. And now, when I remove the line with Application.OleRequired();, I will get the same error as you.

Date: 2005-09-14 09:03
Sender: Jean-Philippe JACOUPY

I tryed, it kinda worked for part of the thread, then by the
end, it crashed.

When I do the "SELECT MAX(ID) FROM Table;" I still get the
error right before "the Reader = CdeDB.ExecuteReader();"
statement. I tryed to use "CdeDB.ExecuteScalar();" method
but it sends the same Exception. I've also tryed to add
again Application.OleRequired(); but it has no effect at
that point. This part is in a function which uses a static

When I use ODBC components instead of OleDb, it works just
Date: 2005-09-12 16:53
Sender: Sławomir Wojtasiak

Try to use Application.OleRequired() in your new thread.
Date: 2005-08-16 20:09
Sender: Nobody

I am getting the same behavior. Has there been any work to fix this issue? It is a show stopper!

Attached Files:

PostgreSQLOleDB - own thread.log


Field Old Value Date By
assigned_toshachar2005-12-01 12:55shachar
File Added48: PostgreSQLOleDB - own thread.log2005-06-21 16:43zeth
Powered By FusionForge