problem accessing database

fguihen

Junior Contributor
Joined
Nov 10, 2003
Messages
248
Location
Eire
my database is in the same folder as my asp page, so i use the mapPath function to try to connect to it using the line:

conn1 = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(".")+ "/db4.mdb");

i then have the the two lines following it:

sql = new System.Data.OleDb.OleDbCommand ("select username,password from users");

this.conn1.Open();

this.dataReader = new OleDbDataReader();

dataReader = sql.ExecuteReader();

it all seems correct to me but i keep getting this error, which i can make no sense of:

System.InvalidOperationException: ExecuteReader: Connection property has not been initialized. at System.Data.OleDb.OleDbCommand.ValidateConnectionAndTransaction(String method, Int32& localState) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.OleDb.OleDbCommand.ExecuteReader() at Upload.Logon.Button1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\upload\logon.aspx.cs:line 72


any ideas at all.its been wrecking my head for two hours now.
 
first of all I never knew you can initialize a datareader
second, you need to give the connection object to the command object

sql.connection=conn1
 
from what i understand, that should bring me to the db4 file in the folder fin which the asp page is in on the server. im prob wrong though as i really dont understand mappath() . il mess with that. thanks
 
Back
Top