Solved

How do I check connection status in data bound forms?

Posted on 2011-03-04
7
281 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 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

20 Experts available now in Live!

Get 1:1 Help Now