Hi,
Declare the Connection object myConn before the try clause and initialize it within the try.
I suggest to change your code as follows:
protected void Names()
{
OleDbConnection myConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=e:\\project\\Db.mdb");
OleDbDataReader myReader = null;
string strQuery = "SELECT TOP 1 Name FROM Names";
try
{
myConn.Open();
OleDbCommand myComm = new OleDbCommand(strQuery, myConn);
myReader = myComm.ExecuteReader();
if (myReader.HasRows)
{
myReader.Read();
Session.Add("Name", myReader[0].ToString());
myReader.Close();
//reuse the myConn connection
strQuery = "SELECT bla bla bla WHERE bla bla bla";
OleDbCommand myComm2 = new OleDbCommand(strQuery, myConn);
myReader = myComm2.ExecuteReader();
}
}
catch (Exception er)
{
Response.Write("Error:" + er.Message);
}
finally
{
if (myReader != null)
{
myReader.Dispose();
}
if (myConn != null)
{
myConn.Close();
myConn.Dispose();
}
}
}