Search code examples
c#ssistoolbox

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


I have a common SSIS C# script task block that we use in our company. It is only a single script block but the script inside is always the same. We use it in lots of our SSIS packages. It is kind of a pain to always have to copy the block from another project or copy the script from somewhere into a new script block.

Is there any way I can put a copy of that script block with the prewritten script into the SSIS Toolbox so I can just drag-and-drop it into our projects?

EDIT:

OK, so I have started writing a custom control based on the advice given below. I've got everything working except for connecting to my SQL Server database. Using the following code:

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())
{

I get this error message:

[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]. ".

What am I doing wrong?

ANOTHER EDIT:

If I change the code to:

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

I get this error message:

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.

If I take out the 'provider' section of the connection string (hard code the string):

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;

I get this error message:

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.

This last block is exactly the code I was using in my Script Task block and it is working fine. I'm just not sure what the difference between the two... :/

FINAL EDIT:

All of these error messages were because my test package was set to run 64-bit instead of 32-bit. I changed the package to run 32-bit and it started working with an ADO.NET connection. My final code looks like this:

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

and it works great as long as it is using an ADO.NET data source. It still would not work with an OleDb data source even using OleDbConnection, etc. Not sure why. But, now that it is working with ADO.NET, I really don't care to solve that one.

Now that the base functionality is working fine, I'm off to write the UI... :)


Solution

  • The only way is to create custom task of it: http://microsoft-ssis.blogspot.com/2013/06/create-your-own-custom-task.html enter image description here enter image description here

    An alternative is to create a custom assembly and reference that in your Script Task: http://microsoft-ssis.blogspot.com/2011/05/referencing-custom-assembly-inside.html