Solved

Uses OLE in a sp run by SQL Server Agent.

Posted on 2014-10-01
5
140 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 48

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 48

Accepted Solution

by:
Vitor Montalvão earned 500 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 48

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
TSQL Challenge... 7 35
Database Integrity 1 49
VB.NET Application Installation with sqlserver 8 30
MS SQL + group by time 4 14
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
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.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

861 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