How to run a ssis package using a sql statement? - sql-server

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.

Related

how to execute tsql scripts from cmdlet written in c#

I want to execute tsql scripts from custom cmdlet written in c#. Can you recommend me the best practice to do it?
I have a few .sql scripts and in my cmdlet I need to iterate through them in specific order and execute each sql script. I also need to run all scripts in transaction if is it possible.
And I need to execute scripts remotely. It means, that there may not be sql server installed on the machine from which is cmdlet executed.
The target sql servers are 2008, 2008R2, 2012.
I have read some approaches, but i'm still not sure what is the best one.
thanks in advance

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

Run sql script from console and not from query analyzer in SQL server

I have written an sql script for updating a database that runs in SQL server 2005.
I want to make those changes to the production DB server but I dont want to run the query from the query analyzer. Is there a way to run the sql script from a console?
create a batch file that points to the script or scripts that you created and run that batch file.
Here follow this tutorial link
You can use sqlcmd. It gets installed together with installing the Query Analyzer.
The sqlcmd utility lets you enter
Transact-SQL statements, system
procedures, and script files at the
command prompt, in Query Editor in
SQLCMD mode, in a Windows script file
or in an operating system (Cmd.exe)
job step of a SQL Server Agent job.
This utility uses OLE DB to execute
Transact-SQL batches.

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.

Execute SQL Server SSIS Package From Stored Procedure

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

Resources