View Single Post
  #1 (permalink)  
Old July 31st, 2004, 10:19 AM
booksnore2 booksnore2 is offline
Authorized User
Join Date: Jun 2004
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default C# handling SQL Server exceptions

Is there anyway in C# that you can check to see if a table exists in SQL Server? Does anyone know of a good resource for learning how to handle C# exceptions specifically relating to calls to SQL Server?

Also in the code below I get a 'Unreachable code detected' warning if I uncomment the lines
// cn.Close();

I'm guessing the datareader and the sql connection will be closed automatically after the return statement. Is that correct? Any help much appreciated.

public SqlDataReader GetReportInfo ()

String connectionString = GetConnectionString();
//get connection string
SqlConnection cn = new SqlConnection();
cn.ConnectionString = connectionString;
SqlCommand sqlCommand = new SqlCommand("select ReportName from ReportInfoTable",cn);
SqlDataReader sqlDataReader;
sqlDataReader = sqlCommand.ExecuteReader();
return sqlDataReader;
// cn.Close();
Reply With Quote