Use Trace.Fail to alert a fail : Trace : Development Class C# Source Code


Custom Search

C# Source Code » Development Class » Trace »

 

Use Trace.Fail to alert a fail








    
 


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();
        }
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Development Class
» Trace