Discussion:
Exception beim Aufruf von ExecuteReader
(zu alt für eine Antwort)
Marc Bogaard
2004-02-19 17:48:02 UTC
Permalink
Hallo!

Ich habe folgendes Problem:

Ich verbinde mit der oledbconnection klasse auf eine access datenbank
(über den verbindungsassisstenten in .net eingestellt). das öffnen
der datenbank mit myconnection.open klappt auch. der state steht auf
open.
allerdings wird beim anschließendne anruf eine exception des typs:

System.InvalidOperationException: ExecuteReader:
Connection-Eigenschaft wurde nicht initialisiert.

hier ist mein quellcode. hoffe einer kann mir einen tip geben.
------------------------------------------------------------------
this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
this.oleDbCommand1 = new System.Data.OleDb.OleDbCommand();

this.oleDbConnection1.ConnectionString = @"Jet OLEDB:Global Partial
Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking
Mode=1;Data Source=""C:\Dokumente und
Einstellungen\Administrator\Eigene Dateien\Visual Studio
Projects\projects\Büchersuche\Bücherliste.mdb"";Jet OLEDB:Engine
Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System
database=;Jet OLEDB:SFP=False;persist security info=False;Extended
Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=False;Jet
OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on
Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User
ID=Admin;Jet OLEDB:Global Bulk Transactions=1";

this.oleDbCommand1.CommandType=System.Data.CommandType.Text;
this.oleDbConnection1.Open();

try{System.Data.OleDb.OleDbDataReader myReader =
this.oleDbCommand1.ExecuteReader();myReader.Close();}
catch (System.Exception myE){Console.WriteLine("hier:
"+myE.ToString());}
this.oleDbConnection1.Close();
---------------------------------------------------------------------------


gruss marc
Günter Prossliner
2004-02-19 18:57:09 UTC
Permalink
| System.InvalidOperationException: ExecuteReader:
| Connection-Eigenschaft wurde nicht initialisiert.
|
| hier ist mein quellcode. hoffe einer kann mir einen tip geben.

Du intialisiert die Connection-Eigenschaft des Command's nicht (wie die
Exception sagt)

| ------------------------------------------------------------------
| this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
| this.oleDbCommand1 = new System.Data.OleDb.OleDbCommand();
|
| this.oleDbConnection1.ConnectionString = @"Jet OLEDB:Global Partial
| ...
| ID=Admin;Jet OLEDB:Global Bulk Transactions=1";
|
| this.oleDbCommand1.CommandType=System.Data.CommandType.Text;
| this.oleDbConnection1.Open();

--> this.oleDbCommand1.Connection = this.oleDbConnection1;

|
| try{System.Data.OleDb.OleDbDataReader myReader =
| this.oleDbCommand1.ExecuteReader();myReader.Close();}
| catch (System.Exception myE){Console.WriteLine("hier:
| "+myE.ToString());}
| this.oleDbConnection1.Close();
| --------------------------------------------------------------------------
-

Problem gelöst?
mfg GP

Loading...