I want to process some records one by one , Need to show record number on .aspx page that currently we are processing nth record.
Setting value of nth record in a label does not work as it will be reflecting only after response come back from server (it does not get refreshed for every record - looks like freezing )
You can use different techniques:
Do server pulling via AJAX request by in some period. Good answered question on this topic - Server polling with JavaScript
Use SignalR to send changes back to client when there was changes on server. You can read about it more here: How SignalR works internally?
Choose one that is applicable in your case
Related
We have a web application that is hosted in IIS. In our database that serves the application we have all kinds of different data values. We are trying to figure out a way to have an email sent to a client if a certain data value exists or exceeds a threshold value.
Generic Example:
Say we have a table that lists widgets and their 'in inventory' quantity. Every time someone sells a widget, this quantity value would be depleted. We want to send an email to the manager when the widget quantity gets below 5 and tell him to reorder more widgets.
We don't want to have sql triggers that check the quantity any time a 'depletion' transaction takes place. Instead, we want some type of background monitoring process that checks the level of the widgets on a timed basis. How can we accomplish this? Windows Service / WinForm application? Something built into IIS that will run ASP.net C# code?
Polling based monitoring should be your last resort. It uses too many resources for a simple task and most of the time it will only see that it's not the case to do anything. And it doesn't even scale when your data grows.
Instead, you should focus on the code that changes those values and act then, on in spot. And the check will also be lighter: only one item being checked not all, and only once, not every x seconds/minutes/hours/...
Apart from the architectural considerations, to answer your question, just as Jonathan said: anything that can read a database and send emails will do, but I'd consider a Windows Service for this job because that's what they were made for: background jobs running all the time, unrelated to the host users. You also get some extra benefits like automatic startup and recovery options.
Anything that can read the database and send an email could accomplish this - console app, winforms app, web app -- it doesn't really matter.
It may be more efficient to monitor when the values are changed (what changes them? A web application?) and have that application also send notifications
Is there a way to cache a user requested data depending upon the user/connection. My situation is that I display the data returned from the WCF in ASP.NET Gridview using paging. The gridview paging displays only 10 items at a time. Whenever the next page is clicked, the service is getting called again (which takes time). After each call the WCF connection is closed. Is there a way to fix this issue? I read upon WCF ASP.NET caching mechanism that caches functions call data and it expires after a certain time. My main thing, is per user/call caching like return 10 items at a time without calling the long running function again for each 10 sets of data. Is there a way to do?
Basically call the function the first time and get 100 items, and return it 10 at a time, without ever running the function again (which gets 100 items)?
I believe that the ASP.NET Gridview always does a postback which result in function call everytime a user changes page. But I maybe proven wrong by someone.
That being said, this may not be the best solution for you. But you could avoid using ASP.NET Gridview in your scenario. When you run a WCF call and return 100 items, you keep them on client side as a JSON file stored in memory, then use jQuery or some other form of javascript to enable users to go through pages without making another function call.
Edited
This may prove useful to you to help you do paging on client-side without having multiple repeated call to the server
http://www.smallworkarounds.net/2009/02/jquery-aspnet-how-to-implement.html
I am developing a Client-Server application using C# .NET Winforms with SQL Server 2008. The client pc's connect to the database server via the LAN.
The task I want to achieve is when an insert (or update or delete) is performed on one client-PC, all other clients must get that update in real-time.
I am currently using timers, so that each client queries the database every 15 seconds then refreshes the gridviews, combo boxes and list boxes. But this makes the application slow and bulky to use.
What is the correct method to use in such scenario. What are such operations called (correct terminology)? Should I use windows services? or same application with background threads ?
First of all, its Windows, so it cannot ever be realtime.
The solutions that – Igby Largeman suggests is well possible. It does have the disadvantage that it can cause very heavvy network traffic, because every time something changes in the database, it is broadcasted to all the clients.
You also have to consider the possibility that something clogs ub the communication between the server and one or more clients, so realtime is out of the question.
that's tricky!
If you really want a user with a grid open on PCA to see data inserted on a PCB without performing any action, you will need a timer to refresh the grid. But I dont think this is a good aproach, you can easily overload the system.
The good practice here is display only the data due to be manipulated. So for example, lets say you want to alter a client's name. You build a search form with a grid where the user can inform search parameters (to filter the data) and once the client is found and altered, you perform another search to the DB to get and display the new data.
But lets say another user had the same grid open showing the client before you perform the alteration. It is showing the old value, but once it clicks on it to see the details, you'll perform a search to the DB to get the new data so that would be ok.
I would like to be able to load data into a DataGrid in Silverlight as it becomes available. Here is the scenario:
My silverlight client fires a WCF call to the server.
The server takes about 1 to 2 seconds to respond.
The response is between 1 MB and 4 MB (quite large).
This data is loaded into a DataGrid.
Although the server responds quickly, the data is not seen by the user until all 1 MB to 4 MB has been downloaded.
What is the best (or most efficient) way to load this data into the DataGrid as it is being downloaded by the client? As opposed to waiting for the download to complete?
A way of handling this is implementing custom virtualization.
Add a webservice method that returns only ids
Add a webservice method that returns a single object by id
Retrieve the ids and load only the visible objects (and perhaps a few more to allow scrolling)
Retrieve more objects when needed for scrolling.
The problem is part of what I was trying to get at with my comment (you still didn't really specify the Datatype for the return), and what Erno gave you a workable solution for. The web service serializes whatever return type you are sending, and will not give you partial results. It's not a question of how you interface with the grid, it's a question of when the web service call on the client says "ok i received the data you need, now continue processing". For instance, if you are gathering up a data table on the server side with 4MB worth of records, then in your service do a :
return MyMassiveDatatable;
Then you are going to have to wait for the entire data table to be serialized and pumped across the wire.
His solution was to break up the transfer into atomic units. I.E. query first for the id's of the records in one web service call, then iterate through those id's and request the record for each id one at a time, and as you receive the one record back, add that to your client side table so that your display writes each record as you get it.
I have a form with a list that shows information from a database. I want the list to update in real time (or almost real time) every time something changes in the database. These are the three ways I can think of to accomplish this:
Set up a timer on the client to check every few seconds: I know how to do this now, but it would involve making and closing a new connection to the database hundreds of times an hour, regardless of whether there was any change
Build something sort of like a TCP/IP chat server, and every time a program updates the database it would also send a message to the TCP/IP server, which in turn would send a message to the client's form: I have no idea how to do this right now
Create a web service that returns the date and time of when the last time the table was changed, and the client would compare that time to the last time the client updated: I could figure out how to build a web service, but I don't how to do this without making a connection to the database anyway
The second option doesn't seem like it would be very reliable, and the first seems like it would consume more resources than necessary. Is there some way to tell the client every time there is a change in the database without making a connection every few seconds, or is it not that big of a deal to make that many connections to a database?
Try the SqlDependency class. It will fire an OnChange event whenever the results of its SqlCommand change.
EDIT:
Note that if there are large numbers of copies of your program running, it can generate excessive server load. If your app will be publicly available, it might not be a good idea.
Also note that it can fire the event on different threads, so you'll need to use Control.BeginInvoke to update your UI.
You can use Event Notifications in SQL Server to raise events in .Net letting you know that the data has changed. See article linked below.
Eric
SQL Server Event Notification
With ASP.Net you can cache query results in memory and setup a dependency that registers with the SQL Server. When something within the data changes the cache is refreshed automatically. Perhaps looking into this might point you in a good direction.
http://msdn.microsoft.com/en-us/library/ms178604.aspx