Solved

How do I check connection status in data bound forms?

Posted on 2011-03-04
7
280 Views
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…
0
Comment
Question by:sonetinc
  • 4
  • 3
7 Comments
 
LVL 18

Expert Comment

by:UnifiedIS
ID: 35040293
Why not disable the print until the data is refreshed?
0
 
LVL 1

Author Comment

by:sonetinc
ID: 35040483
How do I check if the data has been refreshed?
0
 
LVL 1

Author Comment

by:sonetinc
ID: 35041008
I could be polling the textboxes for a change... which denitely is not a clean solution. There must be a better way.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 18

Expert Comment

by:UnifiedIS
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?
0
 
LVL 1

Author Comment

by:sonetinc
ID: 35059056
This is a windows form... not asp.net. 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.
0
 
LVL 18

Accepted Solution

by:
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?




0
 
LVL 1

Author Closing Comment

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

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now