If I want to return the user a web page and write to a log or word by word processing, should I use a stored procedure call from CLR in a new thread or just use sql triggers?
You can't make a SQL Server trigger run asyncronously. The best you could do is utilize SQL Server's Service Broker to execute a stored proc call.
Related
I have a SQL Server procedure which I want to call from an Oracle stored procedure and get the result. Then I need to do some processing on the data.
Can I create something like DB link to call the procedure? Or is there any possible way to do that?
I had this issue solved by contacting DBA and creating gateway then using DBMS_HS_PASSTHROUGH with db link assigned with username, password and database
The specific issue is that I want a SQL Server to connect to an Oracle database and the Oracle database has a Virtual Private Database configured. I need to execute a static stored procedure to enable the VPD to see data. How can I configure SQL Server to fire a stored procedure upon connecting to a remote database? I figure if I can fire a local stored procedure, I can put the remote stored procedure call inside of that. The key is, I need the SQL Server to fire this as soon as it is done connecting to the remote database and before it tries to pass any other queries to it. I'm trying to avoid making the applications do it explicitly.
SQL Server does not offer a solution to my problem.
However, you can setup the service account to have a logon trigger to execute what is needed.
Create Trigger My_User.Logon_Trigger_Name
AFTER LOGON
ON SCHEMA
WHEN (USER = 'MY_USER')
BEGIN
--Do Stuff Here.
NULL;
EXCEPTION
WHEN OTHERS THEN
NULL; --Consume errors so you can still log on.
END;
From a (classic ASP on IIS) web-page a stored procedure is called in SQL Server. The program waits till the stored procedure returns a result but this is not at all necessary. Is there a way to just start the stored procedure and go on?
Mabel
I suggest you to put this SP into the job. Then launch job from IIS. Also you can use asynchronous SP launch (you can read here about it).
I use Misrosoft SQL Server Management Studio to work with databases. I manually started SP execution on PC One. Is there any way to check if SP is still running or not from a different PC?
The system stored procedure sp_who might be of use: http://technet.microsoft.com/en-us/library/ms174313.aspx
If you know the SPID then you can use
EXEC sp_who <spid>;
Alternatively you can use the login name of the login that executed the command
EXEC sp_who 'george\gvee';
If the cmd column states AWAITING COMMAND then this indicates that that session is not performing a query or other action i.e. it is idle
You can use SQL Server Profiler
http://msdn.microsoft.com/en-us/library/ms187929(v=sql.90).aspx
Use a free tool like Idera SQL Check. Shows graphically a lot of statatiscs about the SQL Server current state.
I've a scenario where I've to send a mail after checking a condition after every insert in a table.
Is trigger the right way to do it?
My second question would be as to what approach to take
Should I directly send a mail from the DB. (Note: My DBserver and Mail server are in different networks, might've to create firewall rule exception)
Should I have a CLR-sproc. From the DB, I call the CLR-sproc and CLR-sproc calls a service and from there sends the mail.
Is there a better approach?
Both SQL Server DBMail and a CLR proc will use SMTP to send the email. So, why add complexity?
In addition, sending an email via DBMail or CLR will require processing on INSERT. Note that DBMail uses a queue so will impact less than running a CLR procedure.
A trigger is a good way to do it. However, consider using a stored procedure to do the ISNERT with the email sent outside of the transaction (you'll have an implicit one because of the INSERT). Sending in a trigger means it is part of the implicit transaction for the INSERT.
From a security perspective, SQLMachine still needs access to SMTPMachine, whether using DBMail or a service call by a CLR Proc.
1) Yes, a trigger would be the right way of performing an action after every insert
2) SQL server has a feature called Database Mail which looks like it will do what you want (although I've never used it myself)