Error handling - Gridview connected to datasource

2 posts, 0 answers
  1. amp
    amp avatar
    6 posts
    Member since:
    Aug 2013

    Posted 23 Sep 2013 Link to this post

    Hi,

    I am using a Datasource to populate the gridview. The databinding is done via the propertybuilder at the design time. The Grid works fine when the database connection is established. however when there is an error connecting the database an empty grid is shown and there is no error thrown out.  

    Here is the high level data flow:
    GridView <-> bindingDataSource <-> dataset (mapped to a database table) 

    The dataset is generated automatically and mainly configured via XSD. The database access is done via Integrated Security (via windows authentication)

    Where is the best place to handle database connection error (for example connection failure, user connection reject)?


    .Net version 4.0
    Windows Forms version 2013.2 724

    Thanks
    AMP
  2. Stefan
    Admin
    Stefan avatar
    2911 posts

    Posted 25 Sep 2013 Link to this post

    Hi,

    Thank you for writing.

    Your question does not seem to be connected to RadControls for WinForms or to RadGridView in particular and it seems to be more a general programming question. I would suggest that you address such in the general programming forums like MSDN of Stackoverflow. 

    To point you to the right direction, an exception is thrown when a connection to the database fails, however it is handled exception, hence you do not see it. In order to see it you need to enable Visual Studio to display such exceptions. Please refer to the attached image. 

    To handle the exception, you can use try/catch block:
    try
    {
        this.customersTableAdapter.Fill(this.nORTHWNDDataSet.Customers);
    }
    catch (SqlException ex)
    {
        RadMessageBox.Show("Can't reach database. No data is loaded");
    }

    I hope that you find this information useful.

    Regards,
    Stefan
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top