I'm developing app. using C# and SQL Server 2005,
What i'm trying to do is "Update User Interface when there is change in database",
suppose, there is datagrid on a form..
two different users on different computers -open the form simultaneously.
one user edits some value..
then the same change displayed on the second user's form.
how to do this??
I'm stuck.. help
15 3737
Well, I did it before as a web application not a desktop application. I used JavaScript to do that, even AJAX didn't help me much in my specific case, and a multi-threading implementation.
I think it is difficult what you are seeking, I heard about network stream-socket in c# but didn't try to do, also multi-threading, your application should be implemented according to your case.
Regards,
Bassem
How to automatically tell the connected clients that there is change in database/tables?
I've never done this myself but I'm sure an expert here has....I think you can configure MS Sql Server 2005 to send a notification whenever changes are made.
If it's possible you may be able receive that notification in a .NET application.
If you can do that then the solution you're looking for is probably going to involve Sockets....but I'm not sure what the SQL Server can do so I might be wrong here.
My initial thoughts on this are: - Implement a Socket Server that listens for changes made to the MS Sql
- Server also listens for Socket connections (from clients)
When the Socket Server detects a change made to the MS SQL Server, it sends a notifications to all Socket Connections connected to it. - Implement .NET client applications that use Sockets to connect to the Socket Server....they receive the notification and do whatever you need to do when stuff happens
There is no way that I am aware of to get the SqlServer to send clients notification of changes. (myself being no great expert, so maybe someone else knows)
There is, however, a way for the client to determine if the table has changed: use checksums.
Consider this code sample: - string connstr = @"Server=FAKENAME\SQLEXPRESS;Database=Sample;Trusted_Connection=True;";
-
string sql = "SELECT CHECKSUM_AGG(BINARY_CHECKSUM(*)) AS CHKSUMVALUE FROM Test";
-
SqlConnection conn = new SqlConnection(connstr);
-
SqlCommand cmd = new SqlCommand(sql, conn);
-
long oldsum = 0;
-
conn.Open();
-
do
-
{
-
long newsum = Convert.ToInt64(cmd.ExecuteScalar());
-
Console.WriteLine("Checksum: {0}", newsum);
-
Console.WriteLine("Old Checksum: {0} \nTable{1}changed.", oldsum, (oldsum == newsum ? " has not " : " "));
-
Console.WriteLine("Press 'Y' to checksum again, any key to exit.{0}", Environment.NewLine);
-
oldsum = newsum;
-
}while (Console.ReadKey(true).Key == ConsoleKey.Y);
-
conn.Close();
So, if you dropped that into a console application, and ran it, it would get you an aggregated checksum of your table. Then, while it waits for you to press 'y', you can go make a change in your DB, and then come back and press 'y.' You will notice that the checksum changes.
So, what you can do, is periodically do a checksum from your client. If the most recent checksum differs from the previous one, the table has been updated and must be reloaded.
Thanks a lot @insertAlias, Frinavale and Bassem
I searched in MSDN "Using an Asynchronous Server Socket"
( http://msdn.microsoft.com/en-us/library/5w7b7x5f.aspx )
Will the Socket server send notification to all the thousands of clients?
There will be disaster if one of the client does not receive data change notification..
So, it is not what Yahoo does, right?
I see my browser in yahoo mail box reload every time, something like timer.
Hi guys,
You've all missed the slightly obvious one - SqlCacheDependency class.
It's been a while since I did this but basically you can set up your data to be bound to a SqlDataReader which is linked to a SqlCacheDepedency object. When the data in the underlying database changes, the object will receive a notification that the data has been updated (note: only SQL 2005 support cache dependencies out-of-the-box, for SQL 2000 you have to create a couple of tables - if you Google "SqlCacheDependency" there's plenty of great tutorials on how to set it up), and then you can re-query your SqlDataReader or SqlDataSet as a result.
Hope this helps.
codegecko
PRR 750
Expert 512MB
SqlCacheDependency is more or less like cache, except it monitors a Sql table and update as soon as there is a change in that table. I guess using XMLHttpRequest and updating will be a good option...
I do remember reading something about making your own control: implementing INamingContainer interface overriding the render method ... something like that ...
I dont clearly remember the details... but i guess you could implement a timer ...
:) I love it when I learn something new!
Thanks guys :)
Will the Socket server send notification to all the thousands of clients?
I'm still confused..
@PRR
I used XMLHttpRequest and instead of poll the server after a specific duration I used Thread-Event to control the Response on the server, it was part of my graduation project and it worked fine, minimizing the number of requests to cut off redundant for efficiently using of the available bandwidth. My implementation depended on JavaScript, but it was my case then.
--In the memory of SqlCacheDependency
What if my application doesn't implement a database?
@NitinSawant
Have you attempted to implement what CodeGecko has suggested?
Test that out, and get back to us.
thanx guys,
I used timers and implemented the checksum method, all working fine now.
Thanks again...
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Carlos Eduardo Peralta |
last post by:
Hello:
Can i update a MySQL database with just copy the files MYI MYD and FRM
in the right dir? I know this work. The question is how MySQL manage
the user that are usig that database in that...
|
by: robert |
last post by:
been ruminating on the question (mostly in a 390/v7 context) of
whether, and if so when, a row update becomes an insert/delete.
i assume that there is a threshold on the number of columns of
the...
|
by: Lyners |
last post by:
I have a web page writen in ASP.NET that contains some javascript so that
when a user presses a button, or edits a certain field in a datagrid, another
cell in the datagrid is filled with a value....
|
by: Reney |
last post by:
I have a very weird problem in updating my datagrid. Please help me to solve
it. The datagrid is tied to a dataset table with five columns. Three of them
are primary key and the other two columns...
|
by: Bernie Hunt |
last post by:
I have a simple app that grabs records from a database and steps through
them processing each record. I have three text fields on the form to give
the user feedback on the progress.
With each...
|
by: TJ |
last post by:
Hi All,
I am having some trouble.
I have created a database via the new database option inside VWD2005.
Then and table or two.
I have been able to perform INSERT and SELECT operations on...
|
by: Charles Law |
last post by:
Here's one that should probably have the sub-heading "I'm sure I asked this
once before, but ...".
Two users are both looking at the same data, from a database. One user
changes the data and...
|
by: JohnR |
last post by:
I have multiple controls set to the same database and, normally, when I
change the record in one control the position is also changed in the other
controls because I have "syncwithcurrencymanager'...
|
by: Miro |
last post by:
I will ask the question first then fumble thru trying to explain myself so i
dont waste too much of your time.
Question / Statement - Every mdb table needs a PrimaryKey ( or maybe an
index - i...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |