Do I do dataset fill operations in a using or try block?

Last post 03-25-2007 10:05 PM by btipling. 2 replies.

Sort Posts:

  • Do I do dataset fill operations in a using or try block?

    03-25-2007, 3:41 PM
    • Loading...
    • btipling
    • Joined on 10-08-2006, 8:33 PM
    • Posts 6

    Hi,

     I'm not used to using datacontainers, and I generally use a using statement for sql operations such as:

    using (conn = new SqlConnection(connString))
    {
      //etc
    }
    What about if I'm using a dataset or data adapter. I put the connection in the constructor, but should this be inside a using block?
     Thanks.
    Filed under: , , ,
  • Re: Do I do dataset fill operations in a using or try block?

    03-25-2007, 7:15 PM
    Answer
    • Loading...
    • sbyard
    • Joined on 03-26-2003, 3:42 AM
    • North Yorkshire - England
    • Posts 1,176

    What I do with my sites is put a try catch in all event handlers, since these are called from within the "system", any exception will force the page to fall over.

    Unless I need some special granularity, this minimum of handlers is sufficent

    I also have an SQL table that logs all exceptions, holding the the text of the exception, as well as the stack trace.

    As a last resort, an error page is used to capture anything I missed

    You can then continue with the using statement as this self disposes for you in the pre-compiler

    If it was easy, everybody would be doing it.
  • Re: Do I do dataset fill operations in a using or try block?

    03-25-2007, 10:05 PM
    • Loading...
    • btipling
    • Joined on 10-08-2006, 8:33 PM
    • Posts 6

    Yeah I just went ahead and used a using statement. Works great. Thanks. Smile

     

     

    using (SqlConnection conn = new SqlConnection(_pasteConInfo.PasteConnectionString))
            {
                DataSet data = new DataSet();
                data.DataSetName = "PasteEntries";
                SqlDataAdapter adapter = new SqlDataAdapter("EXECUTE sp_getCode 1", conn);
                adapter.Fill(data, "entryTable");
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(data.GetXml());
    
                XmlWriter writer = null;
                writer = XmlWriter.Create(Response.Output);
                doc.Save(writer);
            }
            Response.End();
      
Page 1 of 1 (3 items)
Microsoft Communities
Page view counter