簡體   English   中英

是否可以將帶有自定義腳本的SSIS腳本塊添加到工具箱中?

[英]Can I add an SSIS script block with custom script into the toolbox?

我在公司中使用了一個常見的SSIS C#腳本任務塊。 它只是一個腳本塊,但內部的腳本始終相同。 我們在許多SSIS軟件包中都使用了它。 總是不得不從另一個項目復制該塊或將腳本從某個地方復制到一個新的腳本塊中,這是一種痛苦。

有什么辦法可以將帶有預寫腳本的腳本塊的副本放入SSIS工具箱中,以便將其拖放到我們的項目中?

編輯:

好的,因此我已經開始根據以下建議編寫自定義控件。 除了連接到我的SQL Server數據庫之外,我已經完成了所有工作。 使用以下代碼:

SqlConnection SettingsConnection = (SqlConnection)_selectedConnectionManagerSource.AcquireConnection(transaction); // Errors here
SqlCommand sp_GetAllValues = new SqlCommand();
sp_GetAllValues.Connection = SettingsConnection;
sp_GetAllValues.CommandType = CommandType.StoredProcedure;
sp_GetAllValues.CommandText = "Get_My_Data_For_Project";
sp_GetAllValues.Parameters.AddWithValue("@project_name", pkgname);
SettingsConnection.Open();
SqlDataReader SettingsReader = sp_GetAllValues.ExecuteReader();
while (SettingsReader.Read())
{

我收到此錯誤消息:

[Connection manager "DevServer"] Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005. An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80004005 Description: "Login timeout expired". An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80004005 Description: "A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.". An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80004005 Description: "Named Pipes Provider: Could not open a connection to SQL Server [53]. ".

我究竟做錯了什么?

另一個編輯:

如果我將代碼更改為:

string myConnectionStr = _selectedConnectionManagerSource.ConnectionString;
SqlConnection SettingsConnection = new SqlConnection(myConnectionStr);
SqlCommand sp_GetAllValues = new SqlCommand();
sp_GetAllValues.Connection = SettingsConnection;
sp_GetAllValues.CommandType = CommandType.StoredProcedure;

我收到此錯誤消息:

Error: The Execute method on the task returned error code 0x80070057 (Keyword not supported: 'provider'.). The Execute method must succeed, and indicate the result using an "out" parameter.

如果我取出連接字符串的“ provider”部分(硬編碼該字符串):

string myConnectionStr;
myConnectionStr = "Data Source=mydatabase;Initial Catalog=mycatalog;Integrated Security=SSPI;";
SqlConnection SettingsConnection = new SqlConnection(myConnectionStr);
SqlCommand sp_GetAllValues = new SqlCommand();
sp_GetAllValues.Connection = SettingsConnection;
sp_GetAllValues.CommandType = CommandType.StoredProcedure;

我收到此錯誤消息:

Error: The Execute method on the task returned error code 0x80131904 (A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)). The Execute method must succeed, and indicate the result using an "out" parameter.

最后一塊恰好是我在“腳本任務”塊中使用的代碼,並且工作正常。 我只是不確定兩者之間的區別...:/

最終編輯:

所有這些錯誤消息是因為我的測試包設置為運行64位而不是32位。 我將程序包更改為運行32位,並且它開始與ADO.NET連接一起使用。 我的最終代碼如下:

string myConnectionStr = _selectedConnectionManagerSource.ConnectionString;
SqlConnection SettingsConnection = new SqlConnection(myConnectionStr);
SqlCommand sp_GetAllValues = new SqlCommand();
sp_GetAllValues.Connection = SettingsConnection;
sp_GetAllValues.CommandType = CommandType.StoredProcedure;

只要使用ADO.NET數據源,它就可以很好地工作。 即使使用OleDbConnection等,它仍然不能與OleDb數據源一起使用。不知道為什么。 但是,既然它可以與ADO.NET一起使用,我真的不在乎解決那個問題。

既然基本功能運行良好,我就可以編寫UI ... :)

唯一的方法是創建它的自定義任務: http : //microsoft-ssis.blogspot.com/2013/06/create-your-own-custom-task.html 在此處輸入圖片說明在此處輸入圖片說明

一種替代方法是在腳本任務中創建一個自定義程序集並對其進行引用: http : //microsoft-ssis.blogspot.com/2011/05/referencing-custom-assembly-inside.html

因此,我認為您遇到了涉及連接的提供程序的障礙:

  1. 您不能在SqlConnection連接字符串中包含provider關鍵字。 SSIS中的所有連接都是OLE DB連接,其連接字符串中包含provider關鍵字。

因此,在您的代碼中,您應該使用OleDbConnection而不是SqlConnection(以及OleDbCommand,OleDbDataReader等)。

對於您的硬編碼連接字符串,您的服務器實例名稱是否碰巧帶有斜線? 這使我絆倒了一次,您必須在C#字符串中轉義斜線,所以如果您的連接字符串是

Data Source=SERVER\INSTANCE;Initial Catalog=DatabaseName;Integrated Security=SSPI;

您的C#代碼應如下所示:

string ConnStr = "Data Source=SERVER\\INSTANCE;Initial Catalog=DatabaseName;Integrated Security=SSPI;";

或(我的偏好)

string ConnStr = @"Data Source=SERVER\INSTANCE;Initial Catalog=DatabaseName;Integrated Security=SSPI;";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM