473,327 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Update User Interface when there is change in database

270 100+
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
Jul 5 '09 #1
15 3737
Bassem
344 100+
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
Jul 8 '09 #2
NitinSawant
270 100+
How to automatically tell the connected clients that there is change in database/tables?
Jul 8 '09 #3
Frinavale
9,735 Expert Mod 8TB
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
Jul 8 '09 #4
Curtis Rutland
3,256 Expert 2GB
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:
Expand|Select|Wrap|Line Numbers
  1. string connstr = @"Server=FAKENAME\SQLEXPRESS;Database=Sample;Trusted_Connection=True;";
  2. string sql = "SELECT CHECKSUM_AGG(BINARY_CHECKSUM(*)) AS CHKSUMVALUE FROM Test";
  3. SqlConnection conn = new SqlConnection(connstr);
  4. SqlCommand cmd = new SqlCommand(sql, conn);
  5. long oldsum = 0;
  6. conn.Open();
  7. do
  8. {
  9.     long newsum = Convert.ToInt64(cmd.ExecuteScalar());
  10.     Console.WriteLine("Checksum:  {0}", newsum);
  11.     Console.WriteLine("Old Checksum: {0} \nTable{1}changed.", oldsum, (oldsum == newsum ? " has not " : " "));
  12.     Console.WriteLine("Press 'Y' to checksum again, any key to exit.{0}", Environment.NewLine);
  13.     oldsum = newsum;
  14. }while (Console.ReadKey(true).Key == ConsoleKey.Y);
  15. 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.
Jul 8 '09 #5
NitinSawant
270 100+
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..
Jul 9 '09 #6
Bassem
344 100+
So, it is not what Yahoo does, right?
I see my browser in yahoo mail box reload every time, something like timer.
Jul 14 '09 #7
JamieHowarth0
533 Expert 512MB
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
Jul 16 '09 #8
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 ...
Jul 16 '09 #9
Frinavale
9,735 Expert Mod 8TB
:) I love it when I learn something new!
Thanks guys :)
Jul 16 '09 #10
NitinSawant
270 100+
Will the Socket server send notification to all the thousands of clients?
I'm still confused..
Jul 18 '09 #11
Bassem
344 100+
@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.
Jul 18 '09 #12
Bassem
344 100+
--In the memory of SqlCacheDependency
What if my application doesn't implement a database?
Jul 18 '09 #13
Curtis Rutland
3,256 Expert 2GB
@NitinSawant
Have you attempted to implement what CodeGecko has suggested?

Test that out, and get back to us.
Jul 18 '09 #14
PRR
750 Expert 512MB
@Bassem
Then i guess you need not worry about caching :) For SqlCacheDependenc you need DB and that too sql server 2000/2005. How to use
some rules to follow
Jul 20 '09 #15
NitinSawant
270 100+
thanx guys,

I used timers and implemented the checksum method, all working fine now.

Thanks again...
Jul 28 '09 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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...
16
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...
13
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....
4
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...
6
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...
2
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...
30
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...
5
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'...
2
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
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...
1
isladogs
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...
1
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)...
1
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
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....
0
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...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.