Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Uses OLE in a sp run by SQL Server Agent.

Posted on 2014-10-01
5
Medium Priority
?
155 Views
Last Modified: 2014-10-13
Hello,

I want to run a stored procedure using SQL Server Agent.

This stored procedure uses OLE and calls sp_AOCreate.

When testing I used the following:

sp_configure ‘show advanced options’, 1;
 GO
 RECONFIGURE;
 GO
 sp_configure ‘Ole Automation Procedures’, 1;
 GO
 RECONFIGURE;
 GO

Open in new window


to enable  OLE.

How should i run this job under SQL Server Agent?

Does running the above script only work for the current session, or does it apply to all uses in the database?
0
Comment
Question by:soozh
  • 3
  • 2
5 Comments
 
LVL 52

Expert Comment

by:Vitor Montalvão
ID: 40354119
It applies to instance so if you already ran those commands to enable the OLE automation now create the job to run the  sp_AOCreate as you would for any stored procedure:
DECLARE @object int;
EXEC sp_OACreate 'YourOLEObjHere', @object OUT;

Open in new window

0
 

Author Comment

by:soozh
ID: 40354123
Hello,

I may not have been clear.  I already have a working SP, that i have tested a few times.  So i know that the code is ok.

What i need to know is how enable the OLE option for SQL Server Agent and this job in particular.

/r
0
 
LVL 52

Accepted Solution

by:
Vitor Montalvão earned 2000 total points
ID: 40354134
You only need to enable it once and will be permanent for the instance but if you only have it enable for running the job and then disable it then you need to put that code in the job and also for disable it after. Like this:
sp_configure ‘show advanced options’, 1;
 GO
 RECONFIGURE;
 GO
 sp_configure ‘Ole Automation Procedures’, 1;
 GO
 RECONFIGURE WITH OVERRIDE;
 GO

---Your code goes here
(...)


sp_configure ‘Ole Automation Procedures’, 0;
GO
RECONFIGURE WITH OVERRIDE;
GO
sp_configure ‘show advanced options’, 0;
GO

Open in new window

0
 

Author Comment

by:soozh
ID: 40354200
ok... thanks for that.. but will the job have to be run as an administrator?
0
 
LVL 52

Expert Comment

by:Vitor Montalvão
ID: 40354205
Yes, you need to provide a user with sysadmin role so it can enable the OLE automation procedure.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question