
一、開啟 SQL Server Business Intelligence Development Studio
1.建立一個Integration Services 專案
2.從工具箱中拉一個 傳送資料庫工作 控制項
3.點擊控制項右鍵 > 編輯
4.選 資料庫 > 連接 新增連接 設定來源及目的地
5.設定完成後 將專案中的 Package.dtsx 檔案複製到自訂的位置
二、開啟 Microsoft Visual Studio 2008
1.建立一個 ConsoleApplication 專案
2.加入參考 Microsoft.SQLServer.ManagedDTS
3.加入程式碼:
using System;
namespace ConsoleApplication1
{
class Program
{
private enum PackageExecutionResult
{
PackageSucceeded,
PackageFailed,
PackageCompleted,
PackageWasCancelled
}
static void Main(string[] args)
{
string dtsxpath = @"C:\Users\shawn\Desktop\SSIS_test\Package.dtsx"; Microsoft.SqlServer.Dts.Runtime.Application app = new Microsoft.SqlServer.Dts.Runtime.Application();
Microsoft.SqlServer.Dts.Runtime.Package pkg = app.LoadPackage(dtsxpath, null); Microsoft.SqlServer.Dts.Runtime.Variables vir = pkg.Variables;
int i = (Int32)pkg.Execute(null, vir, null, null, null);
Console.WriteLine((PackageExecutionResult)i);
Console.WriteLine("-----作業結束-----");
Console.ReadKey();
}
}
}
修改程式碼,加入錯誤報告:
using System;
using Microsoft.SqlServer.Dts.Runtime;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
MyEventListener eventListener = new MyEventListener();
string pkgLocation = @"D:\Package.dtsx";
Application app = new Application();
Package pkg = app.LoadPackage(pkgLocation, eventListener);
DTSExecResult pkgResults = pkg.Execute(null, null, eventListener, null, null);
Console.WriteLine(pkgResults.ToString());
Console.WriteLine("-----作業結束-----");
Console.ReadKey();
}
}
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;
}
}
}
4.執行專案
轉PO自:http://www.clarkrabbit.net/2008/07/tricks-needing-attention-for-ssis.html