Work with real-time data
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: Work with real-time data

  1. #1
    Join Date
    Dec 2008
    Location
    Romania
    Posts
    28

    Work with real-time data

    I have a table with 20.000 records (persons).
    Users on four or five computers insert, update or delete records but must at all times have access to real-time data.
    If a user on a computer marks a person with a flag, or inserts a new person, all the users must see that in real-time.
    Is there a way ?

    I'm using a datagridview to display the information from the persons table.
    Any suggestions please ?

    A stupid solution was to execute a query on each rowenter event of the datagridview and retrieve information directly from the table and display it in text fields, but that does not solve my problem with the inserted records.

  2. #2
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: Work with real-time data

    I think best way to do this is making a client/server application where the client subscribes to the server. If any client makes a change, all subscribed clients are notified.

    A way to achieve this is using WCF.

    Take a look here. This is a simple WCF project where this subscription pattern is used.

  3. #3
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Work with real-time data

    I agree with danny. If you have an object which can raise events when something happens, all you need to do is trap those events from the client side.

  4. #4
    Join Date
    Dec 2008
    Location
    Romania
    Posts
    28

    Re: Work with real-time data

    .NET Framework 2.0

  5. #5
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: Work with real-time data

    Quote Originally Posted by arhicoc View Post
    .NET Framework 2.0
    What do you mean with this? that you are not allowed to use .Net 3.5?

  6. #6
    Join Date
    Dec 2008
    Location
    Romania
    Posts
    28

    Re: Work with real-time data

    Nope. It just means I wonder if there is any solution to achieve this using .NET 2.0.

  7. #7
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: Work with real-time data

    Yes you can achieve the same solution using Remoting. The subscription pattern is the same.

    But why not use 3.5?

  8. #8
    Join Date
    Dec 2008
    Location
    Romania
    Posts
    28

    Re: Work with real-time data

    No reason whatsoever. Will give it a try.
    Thank you very much.

  9. #9
    Join Date
    Dec 2008
    Location
    Romania
    Posts
    28

    Re: Work with real-time data

    Ok, following a simple example found I've got this:

    Client:
    Code:
    namespace Remote
    {
        public partial class Client : Form
        {
            public Client()
            {
                InitializeComponent();
            }
    
            private void Connectbutton_Click(object sender, EventArgs e)
            {
                TcpChannel chan = new TcpChannel();
                System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(chan,true);
                RemoteClass oRemoteClass = (RemoteClass)Activator.GetObject(typeof(RemoteClass),"tcp://localhost:8025/Remote.RemoteClass");
    
                DataSet ds = new DataSet();
                ds = oRemoteClass.RunSql("SELECT * FROM persoane", "persoane");
                dataGridView1.DataSource = ds.Tables["persoane"];
                ChannelServices.UnregisterChannel(chan);
            }
        }
    }
    RemoteClass:

    Code:
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Data;
    using System.Data.Sql;
    using System.Data.SqlClient;
    using System.Runtime.Remoting;
    using System.Runtime.Remoting.Channels;
    
    namespace Remote
    {
        class RemoteClass : MarshalByRefObject
        {
    
            private string _cs = "Data Source=(local);Initial Catalog=tickets;Integrated Security=True;";
    
            public DataSet RunSql(string cSQL, string cTable)
            {
                SqlConnection _connection = new SqlConnection(_cs);
                SqlCommand _cmd = new SqlCommand(cSQL, _connection);
                SqlDataAdapter _adapter = new SqlDataAdapter();
                DataSet _dataset = new DataSet();
    
                try
                {
                    _connection.Open();
                    _adapter.SelectCommand = _cmd;
                    _adapter.Fill(_dataset, cTable);
                }
                catch (Exception exception)
                {
                    throw new System.Exception(exception.Message);
                }
                if (_connection.State != ConnectionState.Closed)
                    _connection.Close();
                return _dataset;
            }
    
        }
    }
    and the Server:
    Code:
    namespace Remote
    {
        public partial class ListenerForm : Form
        {
    
            TcpChannel channel = new TcpChannel(8025);
    
            public ListenerForm()
            {
                InitializeComponent();
            }
    
            private void Listenbutton_Click(object sender, EventArgs e)
            {            
                System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(channel,true);
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteClass), "Remote.RemoteClass", WellKnownObjectMode.SingleCall);
                EventslistBox.Items.Add("http://localhost/Remote.RemoteClass:8025");
            }
    
        }
    }

    I was just wondering how can I make the updates to show on each client window.

    In each client window there is a datagridview.

    Also how can the server be informed of the clients connecting, leaving, making changes etc ?
    Last edited by arhicoc; January 15th, 2009 at 10:33 AM.

  10. #10
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: Work with real-time data

    Only took a quick look, but I believe this is a realtime Remoting example

    http://www.codeproject.com/KB/IP/c_sharp_remoting.aspx

  11. #11
    Join Date
    Mar 2002
    Location
    NY, USA
    Posts
    12,097

    Re: Work with real-time data

    1) Remoting is VERY difficult to get "right" when dealing with cross-machine communication.

    2) WCF is available as an "Extension" so it CAN be used with VS-2005, although it is MUCH preferred to use VS-2008 and .NET 3.5
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009
    In theory, there is no difference between theory and paractice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  12. #12
    Join Date
    Dec 2008
    Location
    Romania
    Posts
    28

    Re: Work with real-time data


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center