?
Solved

How do I check connection status in data bound forms?

Posted on 2011-03-04
7
Medium Priority
?
289 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

840 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