Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


RECONFIGURE inside trigger


RECONFIGURE inside trigger

Author
Message
bozzgo13
bozzgo13
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 1
Hello SQL fans

I am working on one project and got to the point where I have a problem and need your help.

I have a after insert trigger and in it I want to execute Ole Automation Procedures.
The problem is, that sql doesn't allow RECONFIGURE statement within a trigger.

All I want is to execute this lines of code before procedure executen
EXEC sp_configure 'show advanced options', 1
RECONFIGURE
EXEC sp_configure 'Ole Automation Procedures', 1
RECONFIGURE

and disabling it after my stored procedure.

Here is my code

create TRIGGER tr_ORS_CostDrvAfterInsert
ON _tmp1
AFTER INSERT
AS
BEGIN
   
   SET NOCOUNT ON;
   
   
   declare
      @URI varchar(2000) ,
      @methodName varchar(50),
      @requestBody varchar(8000) = '',
      @SoapAction varchar(255),
      @UserName nvarchar(100),
      @Password nvarchar(100),
      @responseText varchar(8000);

   set @URI = 'http://MyURI.php';
   set @methodName = 'GET';
   set @requestBody = '';
   set @SoapAction = 'Method';
   set @UserName = '';
   set @Password = '';
   
   EXEC sp_configure 'show advanced options', 1
RECONFIGURE

EXEC sp_configure 'Ole Automation Procedures', 1
RECONFIGURE


exec [dbo].[sp_ORS_MS_Request]
@URI,
@methodName,
@requestBody,
@SoapAction,
@UserName,
@Password,
@responseText output;


   EXEC sp_configure 'Ole Automation Procedures', 0
RECONFIGURE

EXEC sp_configure 'show advanced options', 0
RECONFIGURE

END


Erland Sommarskog
Erland Sommarskog
SSC Eights!
SSC Eights! (931 reputation)SSC Eights! (931 reputation)SSC Eights! (931 reputation)SSC Eights! (931 reputation)SSC Eights! (931 reputation)SSC Eights! (931 reputation)SSC Eights! (931 reputation)SSC Eights! (931 reputation)

Group: General Forum Members
Points: 931 Visits: 866
Thus, you got a good incentive to reconsider your solution.

I recommend writing a CLR stored procedeure instead of using sp_OAxxxxx.

But you should not make SOAP requests inside a trigger. In a trigger you should do actions that are atomically part of the statement. That is, if the action fails, the statement fails. If the remote host to which you SOAP requests is down, should the statement that fired your trigger fail?

Erland Sommarskog, SQL Server MVP, www.sommarskog.se
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47165 Visits: 44346
The only advice I can offer on that is don't do it. Find another solution. SOAP requests from SQL are not recommended, the OLE automation are fraught with problems and then sticking the whole lot in a trigger...

Look at CLR, also consider service broker for async communications. Add a message to the queue in the trigger and let the queue's activation procedure handle the processing.


Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


ScottPletcher
ScottPletcher
Hall of Fame
Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)

Group: General Forum Members
Points: 3937 Visits: 6663
Agreed, a trigger is not at all the best place for this type of thing.

RECONFIGURE is not allowed to be part of a transaction. A modification trigger is inherently part of a transaction. So, RECONFIG is impossible in this context. Thus, you may have to enable the options permanently.

Also, it's best to avoid all excess overhead in triggers, including declaring unnecessary variables. Thus, maybe something like this:



CREATE TRIGGER tr_ORS_CostDrvAfterInsert
ON dbo._tmp1
AFTER INSERT
AS
SET NOCOUNT ON;
   
declare
@responseText varchar(8000);

exec [dbo].[sp_ORS_MS_Request]
'http://MyURI.php',
'GET',
'',
'Method',
'',
'',
@responseText output;



SQL DBA,SQL Server MVP('07, '08, '09)

Prosecutor James Blackburn, in closing argument in the "Fatal Vision" murders trial: "If in the future, you should cry a tear, cry one for them [the murder victims]. If in the future, you should say a prayer, say one for them. And if in the future, you should light a candle, light one for them."
Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14931 Visits: 38917
also, sp_oa methods can only return 4000 nchars at a time, so your method needs to loop until the responses are complete, and return a nvarchar(max); you probably alreayd have that in your sp_ORS_MS_Request, but if it wasn't consdiered you might get a truncated response.

Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

bozzgo13
bozzgo13
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 1
ok tnx for your answers. I am thinking of using CLR stored procedure. Does anyone have any good example how to do it? tnx in advance.
Erland Sommarskog
Erland Sommarskog
SSC Eights!
SSC Eights! (931 reputation)SSC Eights! (931 reputation)SSC Eights! (931 reputation)SSC Eights! (931 reputation)SSC Eights! (931 reputation)SSC Eights! (931 reputation)SSC Eights! (931 reputation)SSC Eights! (931 reputation)

Group: General Forum Members
Points: 931 Visits: 866
Review this search result from Google for samples on how to write a CLR procedure.

You are not going to call the procedure from your trigger, I hope?

Erland Sommarskog, SQL Server MVP, www.sommarskog.se
Steve Jones
Steve Jones
SSC-Dedicated
SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)

Group: Administrators
Points: 35984 Visits: 18728
We have a piece coming next week on CLR procedures and code.

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search