Of all the Visual Basic.NET data access books that I have purchased and all the Internet site example code that I have reviewed, none have had any good examples of multi-threaded VB.NET code doing data access.
I am trying to avoid the non-responsiveness in a VB app while a simple data retrieval from SQL Server 2005 is in progress.
If anyone knows of any book titles or web sites that have example code (good or not) of multi-threaded VB.NET applications doing data access against Microsoft SQL Server (7, 2000, or 2005) or even against Microsoft Access(TM), it would be very much appreciated if you could provide the book title or URL to point me in the right direction.
The more examples the better.
Thanks in advance.
Sounds like you need to make your calls Async.
http://msdn2.microsoft.com/en-us/library/ms379553(VS.80).aspx
|||I've never seen any database programming books that cover this specific topic. You may want to start by looking for .NET books that cover multi-threaded programming in .NET. From my past experience, I remember it is a bit tricky.
|||
Async ADO.NET2.0- Summary of Best Search Results
The best discussions re async commands (transactions) using SQL Server 2005 that I have found are:
Books:
WROX?’s ‘Professional ADO.NET 2’
Web Articles :
http://msdn2.microsoft.com/en-us/vstudio/aa718334.aspx (Asych Query Samples from Data Access Samples) with source (this is the sample I chose)
www.codeproject.com/dotnet/asynchronousdataaccess.asp (with source)
http://msdn2.microsoft.com/en-us/library/ms379553.aspx (with source), but note warning at:
http://blogs.msdn.com/angelsb/archieve/2004/09/02/224964.aspx
http://nayyeri.net/archieve/2006/08/29/Asynchronous-command-execution-in-.NET-2.0.aspx
http://msdn.microsoft.com/library/en-us/cpgenref/html/cpconAsynchronousExecution.asp
http://msdn2.microsoft.com/en-us/library/ms228972(vs.80,d=printer).aspx
http://msdn2.microsoft.com/en-us/library/ms228975(VS.80).aspx
http://msdn2.microsoft.com/en-us/library/wewwczdw(VS.80).aspx
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconAsynchronousProgrammingDesignPattern.asp
|||
Most books talk about how to do basic async execution from a button click this is fine but the trouble begins when you want to populate the UI with the results of an async db command. The .NET UI is NOT thread safe and you have to serialize everything to the UI thread when doing things like updating a datagrid control for example. If you stick with the data driven events you are OK but if you want to do things more complex it can get troublesome.
I remember doing this back in the old days (.NET 1.0 and 1.1 days) and I would end up with a dead datagrid control with a big red X on it when the grid control got out of sync. So what I finally did after much pain and suffering was write my own custom message passing system that would pass messages to background threads and queue responses back to UI thread, then final bit of data manipulation had to be done on the UI thread.
I remember even creating/manipulating a new datarow on a secondary thread would break the datagrid/dataset (note I would just call NewRow on background thread and then serialize the actual adding of the new row on primary UI thread). This stuff might be fixed in .NET 2.0, so maybe I am being overly cautious here.
No comments:
Post a Comment