-
January 14th, 2009, 02:44 PM
#1
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.
-
January 14th, 2009, 05:16 PM
#2
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.
-
January 14th, 2009, 07:33 PM
#3
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.
-
January 15th, 2009, 03:15 AM
#4
Re: Work with real-time data
-
January 15th, 2009, 03:39 AM
#5
Re: Work with real-time data
Originally Posted by arhicoc
.NET Framework 2.0
What do you mean with this? that you are not allowed to use .Net 3.5?
-
January 15th, 2009, 05:29 AM
#6
Re: Work with real-time data
Nope. It just means I wonder if there is any solution to achieve this using .NET 2.0.
-
January 15th, 2009, 05:33 AM
#7
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?
-
January 15th, 2009, 08:35 AM
#8
Re: Work with real-time data
No reason whatsoever. Will give it a try.
Thank you very much.
-
January 15th, 2009, 11:31 AM
#9
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 11:33 AM.
-
January 15th, 2009, 01:39 PM
#10
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
-
January 15th, 2009, 05:36 PM
#11
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,2010
In theory, there is no difference between theory and practice; 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
-
January 16th, 2009, 01:38 PM
#12
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|