Solved

Uses OLE in a sp run by SQL Server Agent.

Posted on 2014-10-01
5
132 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 45

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 45

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 45

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
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 …
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how the fundamental information of how to create a table.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now