This is a migrated thread and some comments may be shown as answers.

Error handling - Gridview connected to datasource

1 Answer 149 Views
GridView
This is a migrated thread and some comments may be shown as answers.
amp
Top achievements
Rank 1
amp asked on 23 Sep 2013, 05:58 AM
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

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 25 Sep 2013, 08:34 AM
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 >>
Tags
GridView
Asked by
amp
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or