Frage

I am writing a application in C# that needs to do the following:

without connecting to the database I need to check if there are some new logs in database. If there are then I am allowed to open the connection and retrieve them.

So I just need to know if there are new logs (elements) in the database WITHOUT opening the connection to it.

Server can send mail to administrator and I could monitor mailbox for changes but that solution is unacceptable.

Can server on inserting new rows create *.txt file on disk with text indication new rows which I can check and delete/edit after downloading change?

(database is in SQL Server 2008 R2)

Is it even possible? Any/And/Or other options to do this are welcome.

Thank you all very much in advance.

War es hilfreich?

Lösung

Based on the following clarifying comments from the OP under the question:

There is Web application which checks for change every 30 sec and shows latest authorizations. Database is tracking employee authorization and has frequent updates. Now I'm building desktop application, which has local connection to the server and can update more frequently, but client does-not want application to open connection every sec, aldo connection is opened for several ms.

I think that the appropriate solution is a business layer.

If you build a business layer hosted in IIS that performs the database access on behalf of the users using a single database user for access (the application pool user or an impersonated user within the web application), then connection pooling will reduce the number of connections made to the database significantly.

Here is an MSDN article that describes the mechanics and benefits of connection pooling in great detail.

All of the clients, including the web layer, would connect to the business layer using WCF or .Net Remoting (depending on your .Net version), and the business layer would be the only application performing database access.

The added benefit of this approach is that you can move all database access (including from the web client) inside the DMZ so that there is no direct database access from the DMZ outward. This could be a good selling point for your customer.

We use this mechanism extensively for very large, very security and performance conscious customers.

Update

As an alternative, you could have the business layer query the database every 30 seconds, extract the necessary information, and store it locally to the business layer in a database of some sort (Access, Sql Server Express, etc). When requests from clients are received, they will be served from the local data store instead of the database.

You could do this by kicking off a background thread in global.asax's Application_Start event or by adding a cache entry that expires every 30 seconds and performing the work in the cache timeout event.

This will reduce the number of connections to 1 (or 2 if the web isn't modified) every 30 seconds (or whatever the time is).

Andere Tipps

Try to monitor files change date inside DB folder.

If the client desktop application is not going to be deployed massively you could use SqlDependency. Then you wouldn't have to poll the database on a frequent basis, instead the database will notify you if something changes.

You could also deploy a service on the server which uses SqlDependency and then connect to this service from your desktop applications.

If that's not an option this document mentions some other options.

These two could be applied to your situation:

  • Create an AFTER UPDATE trigger on the table being monitored, whose action uses SQL Server Service Broker to send a message to the entity needing the notification.
  • Use Windows Server App Fabric Cache, which supports a change notifications mechanism, based on an in-memory object cache and callback functions you register with the objects.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top