Sylvain Lafontaine
3/19/2005 7:08:00 AM
The ODBC and the OLEDB drivers doesn''t permit to have multiple concurrent
streams opened from the same connection. What''s happening is that these
drivers will open a second anonymous connection when required, giving you
the impression that a single connection is handling multiple stream.
However it''s easy to see that this leads to a lot of problems/bugs when
transactions and other specific features linked to connections (like
temporary tables) are involved (for example because a transaction is always
associated with a single connection and that other connections, including
anonymous connections, cannot be part of it).
These "under the hood" features has been removed from the .NET framework and
if I were you, I wouldn''t hope to much on seeing them in the next release.
If you need two open connections, then all you have to do is to open two
connections; no mess, no fuss.
S. L.
"8870" <8870@discussions.microsoft.com> wrote in message
news:6E97D94C-9D8E-4DB7-95D2-466D4672FE23@microsoft.com...
>I hope the next release of the .net framework will allow multiple active
> DataReaders for ALL connection types (sqlserver, oledb, odbc).
> The version I have (1.1.4322) does not. I cannot understand the reason for
> this limitation (see exception in the following code)
> as the underlying technology, in this case ODBC, doesn''t have this
> limitation.
> The following example is of no use, but it shows the problem.
>
> using System;
> using System.Data;
> using System.Data.OleDb;
> using System.Data.Odbc;
>
> public class test{
> public static void Main(String[] args){
> IDbConnection conn = new OdbcConnection("DSN=...");
> conn.Open();
>
> IDbCommand cmd1 = conn.CreateCommand();
> cmd1.CommandText="SELECT tabname from systables";
>
> IDataReader rdr1 = cmd1.ExecuteReader();
> //rdr1.Close();
>
> IDbCommand cmd2 = conn.CreateCommand();
> cmd2.CommandText="SELECT idxname from sysindexes";
> IDataReader rdr2 = cmd2.ExecuteReader();
> /////////////
> //// Unhandled Exception: System.InvalidOperationException: There is
> already an open
> //// DataReader associated with this Connection which must be closed
> first.
> /////////////
>
> while(rdr1.Read()) Console.WriteLine(rdr1.GetString(0));
>
> for(int i=0; i<10; i++){
> rdr1.Read(); Console.WriteLine(rdr1.GetString(0));
> rdr2.Read(); Console.WriteLine(rdr2.GetString(0));
> }
>
> }
> }