tags:

views:

1304

answers:

2

Hello,

I'm trying to run a simple SSIS package (copies data from an outside folder into a SQL 2005 table). I want to run this package from an Asp.net 2.0 application. Any suggestions?

I have searched many different blogs and websites, but all of these methods lead to failure (usually because of security issues)

dtexec /FILE "name of package" etc.

EXEC master..xp_cmdshell @cmd (supposedly a very bad idea)

sp_start_job

app.LoadPackage(@"\servername\sharename\Package1.dtsx", null)

Thanks in advance for any help you can give me.

+2  A: 

Well, there, Jack, what you've listed is a hodge-podge of half-right answers.

There are a lot of ways to start an SSIS package. However, the best way is probably sp_start_job. Now, this implies that you've created a job that will run your SSIS package.

A lot of times, this puppy fails because of credentials issues. Namely, you're trying to run the bloody thing as the SQL Server Agent account (aka LOCAL SYSTEM), which doesn't bode too well for execution abilities. So, you'll need to create a Credential, and then a Proxy for the job to run as. Therefore, what you need to do is thusly:

CREATE CREDENTIAL MyCred WITH IDENTITY 'CORP\MyUser', SECRET = '<PassGoesHere>'
GO
sp_add_proxy @proxy_name='MyProxy', @enabled = 1, @credential = 'MyCred'
GO
sp_grant_proxy_to_subsystem @proxy_name = 'MyProxy', @subsystem_id = 3
GO
sp_add_job @job_name = 'MyJob', @enabled = 1
GO
sp_add_jobstep 
    @job_name = 'MyJob', 
    @step_name = 'Run SSIS Package', 
    @subsystem = 'CMDEXEC', 
    @command = 'dtexec /F C:\Path\To\Package.dtsx', 
    @proxy_name = 'MyProxy'

Meaningful docs:

  1. CREATE CREDENTIAL
  2. sp_add_proxy
  3. sp_grant_proxy_to_subsystem
  4. sp_add_job
  5. sp_add_jobstep
Eric
Eric, Thanks for you quick response and help with this issue. I probably should have mentioned this, but I don't have access to SSMS. I was lead to believe it was because of how SQL 2005 is set up, but perhaps the DBAs have it completely locked down. In SQL 2000 we could just go to "Data Transformation Services" and "Management" / "SQL Server Agent". Nothing similar is available to me now in SQL 2005.
LizardJack
@Jack: Changed it up to pure SQL. Enjoy.
Eric
Thanks, Eric. I will definitely try this! Is there a way for me to give you points? (I've never used this site before).
LizardJack
@Jack: You can upvote the answer (click the ^ next to it), and you can accept the answer if it solves your problem (click the checkmark under the voting). Upvoting gives me +10, accepted answer gives me +15. That works for any question and answer on this site. Of course, you can only accept answers to your own questions. But you can upvote on any question or answer you see here.
Eric
Thanks, Eric!!! This is embarasssing, but I can't even run the first part of the SQL. "Msg 15247, Level 16, State 1, Line 1User does not have permission to perform this action." I guess I get to see how much the dbas trust us here. I'll keep searching!
LizardJack
+1  A: 

Using an ASP.NET application, server-side wise, is pretty much similar to any other .NET application I guess. I have a code sample here running a SSIS package (SQLServer 2008), but I cannot copy'n'paste it here since I'm on a NDA in this project.

But I can tell you, we are using a namespace called Microsoft.SqlServer.Dts.Runtime.Wrapper, interfaces Package and Application and DTSExecResult enum... and it works fine.

And we are importing an Excel sheet to our database as well.

Edit: Here's the overview of how we do it here: We have Excel sheets that contains data we want to import into our system. Our system is ASP.NET 3.5/Castle Project/SQLServer 2008 powered. Once the user uploads a new sheet into your system, we store it in a folder, let's say "c:\UPLOAD". An action is triggered, so we call our SSIS package to import that into SQL Server 2008.

How we implement it (C#):

Package package;
Application app;
DTSExecuteResult packageResult;

String packagePath = ""; // You have to get your physical path to your package.

app = new Application();
app.PackagePassword = "password"; // We have it here..
package = (Package)app.LoadPackage(packagePath, true, null);
packageResult = package.Execute();

All those classes are from the same namespace, Microsoft.SqlServer.Dts.Runtime.Wrapper, as I stated before.

If you are having access problems, I guess you better ask your DBA to raise your permissions or even create a new one just to run SSIS's packages, since it requires additional levels of permissions.

Hope this can help you.

wtaniguchi
Thanks for your help. I have been trying to use the "Microsoft.SqlServer.Dts.Runtime" class, but maybe adding the wrapper will help.
LizardJack
Hello, just curious if you could provide any more insight to how you got this to work? Eric was helping me below, but I don't have the proper permissions to use his suggestion. Thanks!
LizardJack
Yeah, I will take a look at it, maybe provide you with a "new" example. Editing my answer soon.
wtaniguchi
Thanks! I was trying something very similar, and was getting access problems, so I will need to work with my DBA. I'm currently working with him to allow rights on the sp_start_job sp in msdb. Just curious - I'm assuming the package path would need to be on the server where I deployed it (I don't have SSIS on my pc, or on my application server)?
LizardJack
You will need the DLL's from SSIS, but since the class is loading the file into memory before getting things done with SSIS, I don't see any reason to make this kind of implementation fail when deployed in a different machine.In fact, our project will have different servers for DBs. If you are able to build your application in your dev station, you won't have any problems. Although you will need the DLL that contains the namespace we talked about (I have no problem with that, I'm running a test instance of your database in my dev machine).
wtaniguchi