Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How do I check connection status in data bound forms?

Posted on 2011-03-04
7
Medium Priority
?
287 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
[X]
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
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 1500 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

636 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