Shared datatable only shows data to one client....

Posted on 2006-05-24
Last Modified: 2010-04-17
I have a client/server app using a remoting object that is intended to share a single datatable with multiple clients.  The remoting object is as follows:

Public Class RemConnect
    Inherits MarshalByRefObject

    Public Shared dtAll As DataTable

    Shared Sub New()
        If dtAll Is Nothing Then dtAll = New DataTable
    End Sub
    Public Shared Property GetTable() As DataTable
            Return dtAll
        End Get
        Set(ByVal Value As DataTable)
            dtAll = Value.Copy
        End Set
    End Property
End Class

Then I have a host app that registers the tcp channel and service, executes a SQL query, and fills dtAll.  The clients open a channel on the same port (I listed WellKnown entries at each client and they can "see" the remote object correctly).  When any of my clients connect, dtAll appears to be empty.  If I add the code to run the query from a client, fill dtAll, then bind the client datagrid to dtAll, I see the data correctly on the client that ran the query, but the other client still sees dtAll as "nothing."  I'm not creating a new instance of the remoting object for each call from the client (that is, I'm using "RemConnect.GetTable" rather than Dim RC as new RemConnect, RC.GetTable), so I thought that it would just use an active instance of the object on the server.

Any help on the proper way to share the datatable so that it retains it's data across all instances of the class?  Or am I going at this all wrong for what I'm trying to accomplish?  Thanks in advance for any suggestions.
Question by:feezymac
    LVL 41

    Expert Comment

    Whew... where to begin...

    First of all, most folks don't use .Net Remoting for datatables.   That's because there is a teriffic alternative, namely... a database!    Think about it a second, that's what databases do "for a living".  They offer datatables to remote clients.   Consequently you won't find too many stituations where a program that you write can perform that function better.   This is particulary attractive, since SQL Server 2005 Express Edition is Free!

    On to the specifics of your remoting class...   The key-word "Shared" in this context isn't really applicable.   The term "Shared" doesn't mean what you think it means... instead it means that the object is "static" (or to say it another way), can be called without a specific instance of the object.   In a remoting class, I rather doubt you'd have any shared members (because there's no way to get to the remote object without instantiating it).

    Tell us more about what you're trying to do... perhaps we can provide some useful alternatives

    Author Comment

    Thanks for the reply.

    The reason I was using the datatable is that I'll have about 80 clients trying to connect simutaneously where every 10 or so are requesting an identical set of data and this "dataset" is refreshing every 2 seconds, and they're not sync'd, so it's basically a continuous barrage of queries from different network clients.  This app has to hit the same SQL server as a mission critical app for the company (they've been hesitant up to this point to even give me access), so I was trying to minimize the SQL server traffic as much as possible:  I was thinking that using the server app to query once (vs. 80 individual queries), parsing that dataset out to individual datatables, then distributing these to the appropriate clients (through the server app, which lives on another app server) would be less stressfull on the SQL server itself.  Honestly, the dataset is so small and the query so straight-forward (only 1 join) that I think the clients could connect directly without impacting the "main" app's performance, but again our IT staff is being anal about the whole thing.

    Another idea I was tossing around was to have my server app run the query and use it to update a SQL server on another machine (any machine besides that dreaded mission critical SQL server) then just point the clients directly to that, so a dedicated SQL server just for this app.  Only problem there is I would have to go back to IT to request another box :)

    Thanks again for the reply and any other ideas you have.
    LVL 41

    Accepted Solution

    How about the idea of a 2nd SQL server that handles just this one DataTable for your 80 clients?   This "head end" database would handle the load of your clients without any increase in traffic from the "real" backend mission critical database.  You could use SQL Server's own replication feature to syncronize the "head end" database with the backend database.

    ... just a thought

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: HTML5 Mobile App Development with PhoneGap

    PhoneGap can help you leverage your already existing HTML5, JavaScript, and CSS skills in order to create and deploy cross-platform mobile apps.This program comprehensively covers HTML5 mobile app development from top to bottom.

    Suggested Solutions

    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    This is about my first experience with programming Arduino.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    761 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

    8 Experts available now in Live!

    Get 1:1 Help Now