Link to home
Start Free TrialLog in
Avatar of sonetinc

asked on

How do I check connection status in data bound forms?

I have a simple form in my .Net application: form with a combobox and textboxes bound to a SQL database. The user can browse data records by changing the combobox selection and print the select record.

When the application is idle for a longer period the DB drops the connection. Later when the user comes back and makes a quick selection change the data is not being supplied quickly enough to the text boxes. Clicking the print button, the application sends data from the previously selected record to the print function without any error messages (although at that time the combobox has different ID selected (before the DB connection is reestablished).

How can I check the DB connection status and catch this error?

The textboxes are bound with the following command:

textBox1.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.credentialsBindingSource, "FirstName", true));

Any help is greatly appreciated…
Avatar of UnifiedIS

Why not disable the print until the data is refreshed?
Avatar of sonetinc


How do I check if the data has been refreshed?
I could be polling the textboxes for a change... which denitely is not a clean solution. There must be a better way.
Does the combo box force a postback?  Are you saying they change the combo value and click print before the postback occurs?  And your print function prints what is in the controls as opposed to values from the database?
This is a windows form... not And yes... this is exactly what is happening. After a few seconds the connection to the DB is reestablished and all textboxes are updated with the corresponding values from the DB. While the connection is being reestablished the user can click the submit button and print with old values.
Avatar of UnifiedIS

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Was not able to find any "clean" way to check the connection state. I'm accepting the solution as a workaround.