How do I check connection status in data bound forms?

Posted on 2011-03-04
Last Modified: 2012-05-11
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…
Question by:sonetinc
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 18

Expert Comment

ID: 35040293
Why not disable the print until the data is refreshed?

Author Comment

ID: 35040483
How do I check if the data has been refreshed?

Author Comment

ID: 35041008
I could be polling the textboxes for a change... which denitely is not a clean solution. There must be a better way.
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

LVL 18

Expert Comment

ID: 35056538
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?

Author Comment

ID: 35059056
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.
LVL 18

Accepted Solution

UnifiedIS earned 500 total points
ID: 35059211
Here are some ideas:
You could clear the textboxes when the selectedindexchanged event from the combo box fires.  This would prevent incorrect data from printing.
You could try to keep your connection from timing out by periodically using it.
You could use unbound text boxes so you would know when the fields had been updated.
You could bind one text box to the key value from your combo box and do a compare before the print.  If the text box has the correct ID, then allow the print.  Put that check in a loop and continue polling until it matches.

Does your binding object have any events that signify the data has been updated or is being updated or anything like that?


Author Closing Comment

ID: 35761034
Was not able to find any "clean" way to check the connection state. I'm accepting the solution as a workaround.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL ( and MongoDB (…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question