Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Caching / January 2008

Tip: Looking for answers? Try searching our database.

SqlDependency with Notification : thread synchrnization issue

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joe Abou Jaoude - 29 Jan 2008 08:00 GMT
Hi,

I m trying to use the SqlDependency with the Notification feature of SQL
SERVER 2005.
I load the data from the database in a Shared datatable (if the
datatable is empty).
When SQL SERVER notifies my app that a change has been made I clear the
datatable.
The code works fine, however I noticed that without a thread
synchrnization it can cause a problem.
Here's the code:
Dim dt As DataTable = MyDependency.GetCache()
GridView1.DataSource = dt
GridView1.DataBind()

MyDependency.GetCache() returns the Shared datatable.
If a change is made to the data while it's being bind a problem occurs.
To resolve the problem I tried to use the Monitor class as follow:

Dim dt As DataTable = MyDependency.GetCache()
Monitor.Enter(dt)
GridView1.DataSource = dt
GridView1.DataBind()
Monitor.Exit(dt)

However this method didn't prevent the datatable to be cleared by the
notification thread.

What I m doing wrong and what's the right way to resolve this issue.

Thank you.
Ravi - 30 Jan 2008 05:13 GMT
Hi Joe,
        "However this method didn't prevent the datatable to be cleared by
the
notification thread." This is anyways the expected behaviour.
"What I m doing wrong and what's the right way to resolve this issue."
Well it depends. If you want your cache items to beevicted at any case then
leave it as it is. If its ok to have little bit stale data then create a copy
of datatable in your GetCache() method and return it. This will prevent
getting exceptions while DataBinding happens.

Hope this helps.

> Hi,
>
[quoted text clipped - 29 lines]
>
> *** Sent via Developersdex http://www.developersdex.com ***

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.