using System;
using System.Data;
using System.Data.SqlClient;
using System.Threading;
using System.Diagnostics;
class Class1 {
[STAThread]
static void Main(string[] args) {
SqlConnection dbConn = new SqlConnection("server=.;database=pubs;uid=sa;pwd=");
SqlCommand dbComm = new SqlCommand("SELECT * FROM " + "authors", dbConn);
SqlDataReader dr = null;
Trace.WriteLine(DateTime.Now + " - Executing SQL statement");
try {
dbConn.Open();
Trace.Assert(dbConn.State == ConnectionState.Open,"Error", "Connection failed...");
dr = dbComm.ExecuteReader(CommandBehavior.CloseConnection);
Trace.Assert(dr != null, "Error","The SqlDataReader is null!");
while (dr.Read()) {
}
} catch {
Trace.Fail("An error occurred in database access");
} finally {
if ((dr.IsClosed == false) && (dr != null))
dr.Close();
}
}
}