none
WPF Application Crashes establishing SQL Connection RRS feed

  • Question

  • I have a WPF applicaiton which uses TableAdapters to access our SQL Server. Using VS 2005 to create the tables is nice until you need to know what is happing behind the scene in order to capture exceptions.

    I have already extended the TableAdpaters to include some custom methods but can anyone tell me what methods to override or extend to capture server access exceptions. In my case I changed the connection string so that it would fail in order to start trying to figure out how to handle this exception.

    Thanks,
    Jeff


    Wednesday, November 14, 2007 2:20 AM

Answers

  • The exception is caught when accessing the data. Now I need to restructure my code a bit to better handle error handling.

                try
                {
                    dt = ta.GetData();

                    foreach (MtiProducts.PRODUCTLINESRow row in dt)
                    {
                        if (row.DIMENSION2_ != "")
                            Add(new StoredProperty(row.DIMENSION2_));
                    }
                }
                catch(Exception e)
                {
                    System.Windows.MessageBox.Show("Error: " + e.ToString());
                }
    Wednesday, November 14, 2007 7:38 PM

All replies

  • It does not appear that the "private void InitConnection()" method can be overridden. I read that non-captured execeptions bubble up but it is still not clear how to capture these exceptions as they float up.  The one example I found related to ASP.NET and displaying a better message to the web user. I don't see how this applies to a WPF standalone application.

    I think I need to put a try/catch at the App level. If this is the case, is there an example to be had somewhere?

    Thanks,
    Jeff
    Wednesday, November 14, 2007 5:35 PM
  • The exception is caught when accessing the data. Now I need to restructure my code a bit to better handle error handling.

                try
                {
                    dt = ta.GetData();

                    foreach (MtiProducts.PRODUCTLINESRow row in dt)
                    {
                        if (row.DIMENSION2_ != "")
                            Add(new StoredProperty(row.DIMENSION2_));
                    }
                }
                catch(Exception e)
                {
                    System.Windows.MessageBox.Show("Error: " + e.ToString());
                }
    Wednesday, November 14, 2007 7:38 PM