Normally, you try to spend as little time with a connection open as possible. You open late and close early. If this means you open and close a few times, well, that's better than leaving something open.
I posted a snippet on this pattern
here.
The next thing you can do is see how to shorten the database trips. The code you offer here need only visit the database once.
Given what you've written, I might write it like so:
CODE
DataAccess DA = new DataAccess();
SqlDataReader reader = null;
SqlCommand cmd = new SqlCommand("select"
+ " a.LoginID, a.Login, a.Password, b.PartnerID"
+ " from Login a"
+ " left outer join Partner b on a.LoginID=b.LoginID"
+ " where a.Login = @Login"
+ " and a.Password = @Password"
);
cmd.Parameters.AddWithValue("@Login", userIDTextBox.Text);
cmd.Parameters.AddWithValue("@Password", passwordTextBox.Text);
try {
//I'm assuming DA.GetDataReader opens the connection,
// otherwise you wont get very far.
reader = DA.GetDataReader(cmd);
if (reader.read()) {
Session["LoginID"] = Int32.Parse(reader["LoginID"].ToString());
Session["PartnerID"] = Int32.Parse(reader["PartnerID"].ToString());
} else {
loginFailedLabel.Text = "Login Failed.";
//loginFailedLabel.Text = DA.WriteError();
}
} catch (SqlException exception) {
loginFailedLabel.Text = DA.WriteError("REACH.Master.cs: Line: " + exception.LineNumber + ": " + exception.ToString(), true);
return;
} finally {
if (reader!=null) { reader.Close(); }
DA.CloseConnection();
}
Hope this helps.