Created
January 23, 2021 09:57
-
-
Save ricoisme/15288c108f9cc70583d9dcfcbe8e92c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using Microsoft.SqlServer.Dts.Runtime; | |
using System.Collections.Specialized; | |
using System.Configuration; | |
namespace ExecuteSSIS | |
{ | |
class MyEventListener : DefaultEvents | |
{ | |
public override bool OnError( DtsObject source, int errorCode, string subComponent, | |
string description, string helpFile, int helpContext, string idofInterfaceWithError ) | |
{ | |
// Add application-specific diagnostics here. | |
Console.WriteLine( "Error in {0}/{1} : {2}", source, subComponent, description ); | |
return false; | |
} | |
} | |
class Program | |
{ | |
static void Main( string[] args ) | |
{ | |
string pkgLocation; | |
Package pkg; | |
Application app; | |
DTSExecResult pkgResults; | |
Variables vars; | |
//讀取組態檔 | |
var section = ConfigurationManager.GetSection( "appSettings" ) as NameValueCollection; | |
string value = section[ "type" ]; | |
MyEventListener eventListener = new MyEventListener(); | |
pkgLocation = @"e:\Package.dtsx"; | |
app = new Application(); | |
pkg = app.LoadPackage( pkgLocation, eventListener ); | |
vars = pkg.Variables; | |
vars[ "strtype" ].Value = value; //設定 SSIS 變數 | |
pkgResults = pkg.Execute( null, vars, eventListener, null, null ); | |
Console.WriteLine(string.Format("執行結果:{0}", pkgResults.ToString()) ); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment