Execute SQL Server SSIS Package From Stored Procedure - sql-server

I have a SSIS package that is stored in a SQL Server 2005 DB. I am trying to execute this package from a stored procedure on the same server. Is there a better way than exec master..xp_cmdshell 'dtexec /SQL...
I am running into (I think) file system permission issues with xp_cmdshell that is preventing execution

I don't think so, here are two good articles:
http://www.simple-talk.com/sql/sql-server-2005/executing-ssis-packages-/
http://www.codeproject.com/KB/database/Call_SSIS_from_SP.aspx

I recommend using Agent instead:
Create Agent proxy account for the account that will run the job
Create Agent job that runs this package
Make it use the proxy account created in #1
Test the job
In SQL code, use sp_start_job to start this job
The downside is that you can't easily pass the parameters from SQL to the package this way.

Since 2012, MSSQL has an SSIS Catalog, where you can park your packages there. You can then execute a package with parameters. This way we can avoid xp_cmdshell to call dtexec, or sp_start_job without parameters. Key SPs: create_execution, set_execution_parameter_value, and start_execution.
From MSDN:
To run a package on the server using SQL Server Management Studio
Deploy and Execute SSIS Packages using Stored Procedures

Related

SQLCMD, PowerShell, BCP tool coded in stored procedure -SQL Server Managed Instance

I am planning to migrate a legacy application which was using SQL Server 2012 to latest SQL Server managed instance on Azure.
But I doubt it will work, because my database has lots of stored procedures which use SQLCMD and BCP tools.
For example:
EXEC master..xp_cmdshell #cmd;
FTP commands, PowerShell copy command which involves actual file storage.
It will execute fine on a standalone Windows machine where we have actual storage like C:/ or D:/
But how it will behave in latest SQL Server Managed Instance on Azure?
Please can you suggest any idea?
Will the same stored procedure code work fine in latest SQL Server Managed Instance on Azure?
xp_cmdshell is not supported on Azure SQL Managed Instance. Either migrate that stuff to a different solution, or use SQL Server on Azure VMs, which is super easy to set up and operate.

Can not find the stored procedure error in SQL Server Agent job with ssis package

An SSIS package which consists of an Execute SQL task is running fine when executed in the SQL Server 2014 catalog.
When this is a part of a SQL Server agent job, it throws an error
can not find the stored procedure
The package's Execute SQL task contains the statement
exec usp_procedures
The definition of this stored procedure is to execute multiple other stored procedures:
exec usp_strdproc1
exec usp_strdproc2
exec usp_strdproc3
exec usp_strdproc4
All of the sub procedures are accessing files in a particular location. I have ensured that the SQL Server agent job has all the permission to access the file
I would immediately think its a permission issue, but you have checked that.
Next check what schema you should be using and whether thats set up correctly?
Is the SQL Server Job Agent running on the same server?
Have you pointed the job to the correct database?
Hope this points you in the right direction.

Is it possible to execute an SSIS package remotely?

I want to execute an SSIS package stored on an SQL server (2008 R2) from another computer. However, everything I've found online involves loading the package from the server and then running it locally.
Is it possible to run the package on the server? Any resources are appreciated.
To execute a package, you normally create a new job and use a job step to start the desired package.
If you got the sql server management studio(ssms) installed on your remote computer, you simply connect to the database engine and start the job. Alternativly, you can connect to the integration services with ssms and start the package directly.
If there is no ssms available, you can start the job using the stored procedure sp_start_job. You could use something like this to execute.
You could execute the stored procedure sp_start_job in the remote server. I've used it (creating a stored procedure to control a bit the parameterisation) succesfully.
http://msdn.microsoft.com/en-us/library/ms186757.aspx

Database task to delete table records periodcally in sql server 2008

I want to add a database task that runs on a 6 hours interval. The task is to delete some records that matches certain condition.
What is the best way to achieve this in Sql Server 2008 ?
I know I can do this on the app side but I want it on sql server side.
You can use Sql server agent to run a job periodically. The job can do anything you want such as executing stored procedure which will do the actual cleaning.
Set up a task as maintenance task / scheduled task in the SQL Server admin.
There are several options. Two I would suggest:
Set up SQL Agent Job, with a T-SQL step in it. In the step details you will select target database and type in SQL statement to delete rows.
Create SSIS package; use Execute SQL Task and define SQL statement there. Then create SQl Agent Job to call the SSIS package.
(1) has a limitation - it will only be able to run the script against a database locate in the same instance of the SQl Server as SQl Agent, unless you use Linked servers.

How to run a ssis package using a sql statement?

i'm using Sql Server 2008. There are options to run from command line. Is there a way to execute an ssis package using sql statement?
-Vivek
Im my experience one of the easiest way to control them from within SQL is not to try an xp_cmdshell etc but to add a job that executes the SSIS package as the first step and then from within the SQL msdb.dbo.sp_start_job 'yourjobname'
This also makes it easy to control which account (via proxy / credential) the job gets run under.

Resources