title: How to handle SQL Query CommandTimeout in C# 2.0
body: <p>I have got below code in c#.</p>
  
  <pre><code>SqlConnection conn = new SqlConnection("Data Source=MANOJ-PC\\SQLEXPRESS;Initial Catalog=master;Integrated Security=False;User Id=sa;Password=Manoj;");
  conn.Open();
  
  if (conn != null)
  {
      //create command
      SqlCommand cmd = new SqlCommand("dbo.GETTridionLinkData", conn);
      cmd.Parameters.AddWithValue("@PageID", "637518");
      cmd.CommandType = CommandType.StoredProcedure;
      cmd.CommandTimeout = 500;
      StringBuilder sbXML = new StringBuilder();
      //Adding Root node
      sbXML.Append("&lt;TridionLinks&gt;");
  
      //Reading all the values of Stored procedure return
      using (XmlReader reader = cmd.ExecuteXmlReader())
      {
          while (reader.Read())
          {
              sbXML.Append(reader.ReadOuterXml().Replace("//", "/"));
          }
      }
  
      //Closing the root node tag
      sbXML.Append("&lt;/TridionLinks&gt;");
      XmlDocument xDoc = new XmlDocument();
  
      //Loading string xml in XML Document
      xDoc.LoadXml(sbXML.ToString());
  }
  </code></pre>
  
  <p>In above code you can see that, I have set the <strong>cmd.CommandTimeout = 500;</strong>, now I want to give user an error message if the timeout is more than this or you can say database is down.</p>
  
  <p>Please suggest!!</p>