Set a SQL trigger and have asp.net subscribe to it? - asp.net

Is it possible to set a SQL trigger, where if it gets fired, do something in an asp.net application?

Theoretically YES (via SQL CLR Stored Proc calling a web service in
that asp.net app)
Psychologically NO
You'd be better using a queue or log table, write to that and have a service or task subscribe to it.

EDIT: Excuse me... taht technology is deprecated, and now you should use:
SQL Dependency class
DEPRECATED:
You can use SQL Server Notification Service.
Look at this article:
Understanding SQL Server 2005 Notification Services with ASP.NET 2.0
It uses right the same technology that SqlCacheDependency Class which could also help you, depending on what exactly you want to achieve.

Related

Notifying a webservice based on table insert

I have a requirement where third party software running on a desktop will write to a local database and I need to send some of that information to a remote web service. I don't have any control over the thirdparty software that is doing the insert but I can read the database.
My approach is to have a windows service check the local table every second for an insert, if there is an insert send the webservice request. I don't like checking every second but this whole process needs to happen in a short amount of time after the insert. Is there a better way to go about this? Some kind of listener? I don't think I can use triggers.
This will be .NET and SQL Server if that matters.
Try using the SQLDependency class. Implement the onChange method of the class to handle your processing. The following article describes the process of configuring your environment and has some sample code for this.
http://www.codeproject.com/Articles/144344/Query-Notification-using-SqlDependency-and-SqlCach

Customize the CSLA server side initialization

I have next problem. We have a huge client-server system and use CSLA to operate with DB data. There are a set of WinForms-based clients and one WCF-based AppServer. We have custom logging subsystem and settings for this subsystem are stored in DB. So on initialization of each side of our system (client application or application server) we need to configure logging subsystem with settings from DB. In the client application it is easy to do. But how can we extend CSLA WCF Portal to init logging after init of CSLA WCF Portal??
So, how to customize the initialization of CSLA?
Thanks a lot!!
Rockford Lhotka answered this question on his forum http://forums.lhotka.net/forums/p/9224/43785.aspx#43785
In CSLA 3.8 and higher there's one hook that exists on the server before anything else occurs. It is designed to enable authorization on every single server call, but it can be used to perform server-side initialization as well.
You need to implement Csla.Server.IAuthorizeDataPortal and add a config entry so the data portal knows the assembly qualified type name of your class that implements the interface.

How to cancel a long running database insert/update operation from ASP.NET UI when the the operation is being oerformed by a Windows service

I see a question about this here.
However, in my case, It is the windows service which in running the long running insert/update on a table and I need to cancel the operation from my ASP.NET application.
In the above link Burnsys suggests that one should kill the Sql server session. Is that really only way and a goood practice to do this?
Also, in the same poset somebody suggests one can use SqlCommand.Cancel to cancel. However, I am not sure how can I cancel the command from the windows service from ASP.NET application.
Please advice.
Thanks in advance for all your valuable comments,
Ashish
1) If you can change the code of windows service or stored proc, I suggest creating some table on sql server to store states of long running task. Windows service (than could be executed by service) would add records to this table. ASP.NET application would monitor this table (manualy) to stop any runnning process.
If you still using sql server 2005, you still can use KillProcess(ProcessId). So store processId to this table and asp.net application can send kill process command to sql server (if you have permissions).
2) If you have any programming (wcf for example) interface of service that hosted in windows service, so I suggest exetuting LR task asynchronously and add method to cancel this task. ASP.NET application could call this cancel method.
SqlCommand command = new SqlCommand();
command.BeginExecuteNonQuery();
...
command.Cancel();

How To Implement ReverseAJAX (Comet) in ASP.Net MVC

How could I implement a Comet architecture in a ASP.Net MVC?
The paid alternative
There are great comments about the question in this thread.
And based in the fact you can use handlers in a MVC app:
WebSync
will do the work : )
As long as you need to implement server push support onto your ASP.NET MVC application you will need some extra functionalities like detection of client status etc. I suggest you to try PokeIn comet ajax library which you can find sample project here
I doubt you will find something out of the box for MVC but you can always implement the client side code that handles timeouts and reconnects to an AJAX-enabled WCF service that polls for whatever event you want to be notified for. Be sure to set the timeout of the service to a higher value.
Edit 24.11.2013
Since the original question was posted SignalR was released which is a library to do just that.

Query Notification Error

We have this weird issue regarding SQL Query Notification service.
We have a main web application running with QN service so the cache item in the web get notification from SQL when the monitoring data changed. And it runs well.
What is weird is when the other supporting web service tries to register QN subscription into SQL 2005 SP2 and this error occurs
"System Exception: SqlDependency.Start has been called for the server the command is executing against more than once, but there is no matching server/user/database Start() call for current command "
This error only happen when SQL query in SQLDependency against particular instance DB. The other instance DB works just fine.
There are not much resource can be found for QN / service broker issues. Wish anyone has similar experience can share their knowledge.
This is one of those SQL Server subject areas where there are not too many knowledge experts available out there, inluding dare I say, myself ;-)
My suggestion would be to post your query on the official SQL Server Service Broker Forum over at MSDN. Link below for reference:
http://social.msdn.microsoft.com/Forums/en-US/sqlservicebroker/threads
this means that the Start() method has already been called for this DB.
the start method has the restrictions you can see here at the bottom.
This is not a direct answer on the topic, but on the issue of QN/SSB resources I have a few articles on my site:
http://rusanu.com/2006/06/17/the-mysterious-notification/
http://rusanu.com/2008/01/04/sqldependencyonchange-callback-timing/
http://rusanu.com/2007/11/10/when-it-rains-it-pours/
http://rusanu.com/2005/12/20/troubleshooting-dialogs/
I am a former developer with the SQL Server team and I was involved with both Service Broker and, to more or less degree, with its in-house uses like Query Notifications and SqlDependency, Event Notifications, dbMail etc.

Resources