How do I set project parameters? - vb.net

In a package located in the SSISDB node I am trying to execute, I have one package parameter and one project parameter.
I am able to set the package parameter by providing ExecutionValueParameterSet to the execute method. It is something like this:
Dim setValueParameters As New ObjectModel.Collection(Of PackageInfo.ExecutionValueParameterSet)
Dim exp As New PackageInfo.ExecutionValueParameterSet
exp.ObjectType = 30
exp.ParameterName = sp.Name
If sp.Value IsNot Nothing Then
Select Case sp.TypeCode
Case TypeCode.String
exp.ParameterValue = sp.Value
Case Else
exp.ParameterValue = Convert.ChangeType(sp.Value, sp.TypeCode)
End Select
End If
setValueParameters.Add(exp)
package.Execute(use32BitRuntime, er, setValueParameters)
Now, this works fine for package parameters. But I cannot set parameters on the project level.
I have tried the following:
package.Parent.Parameters(sp.Name).Set(ParameterInfo.ParameterValueType.Literal, sp.Value)
However, I still get errors that the parameter is missing. If I check package.Parent.Parameters(sp.Name).ValueSet parameter after setting it is false.
Any ideas?

The problem was the ObjectType. The magic number assigned to them has meaning.
20 Project Parameter
30 Package Parameter
50 Execution Parameter
You can also get an idea of what is available by querying the integration services catalog
SELECT * FROM SSISDB.catalog.object_parameters AS OP
See also
Execute SSIS 2012 Package with Parameters via .Net

Thanks to #billinkc I found that I should set project parameters on the same ExecutionValueParameterSet but use exp.ObjectType = 20 for project parameters.

Also see this SSIS WIKI page about parameters:
http://social.technet.microsoft.com/wiki/contents/articles/21978.execute-ssis-2012-package-with-parameters-via-net.aspx

Related

How do you see what SQL IronSpeed sends to the database?

I'm using IronSpeed Designer 12.2 and trying to write custom SQL in a WhereClause override. The custom SQL I wrote and submitted in the WhereClause is throwing an SQL exception, but I can't see the SQL IronSpeed is sending to the database. Without the SQL, I cannot troubleshoot.
I can't find where the SQL is submitted to the database, such as by an ExecuteReader method call.
I'm using a statement like this:
if (MiscUtils.IsValueSelected(this.MyFilter)) {
String sql = "(EXISTS (SELECT TOP 1 CompanyId FROM Collateral as c WHERE CODE = '{0}' AND c.CompanyId = Company.CompanyId))";
wc.iAND(String.Format(sql, this.MyFilter.SelectedValue));
}
I know my WhereClause SQL is correct when used outside of IronSpeed because I copy-pasted it from a query working directly in MSSQL. However I can't see how IronSpeed combines it with its internally-generated SQL after it becomes a WhereClause.
I'm hoping someone has experience with this issue and can point me in the right direction. Thanks for the help!
If you look for answer long enough, you can find it yourself. Here's how I found you can examine the SQL sent to the database:
Go to C:\Program Files\Iron Speed\Designer v12.2.0.
Copy the BaseClasses folder to the root of my IronSpeed solution folder.
Add the existing BaseClasses project to the IronSpeed solution.
Delete the existing references to baseclasses.dll from the projects in the IronSpeed solution (I'm using a web app rather than web site project).
Add references to the BaseClasses project now included in the solution.
Open the file MicrosoftDynamicSQLAdapter.vb.
In method GetRecordValuesEx(...), go to line 1514 statement "reader = SqlTransaction.ExecuteReader(myCommand, cmdBehavior)" and set a breakpoint on this line.
Run the project. When the breakpoint is hit, examine the command of myCommand object.

Trying to run a Directory.Exists() with a system variable vs drive letter

I am trying to run a C# program to determine if a directory exists on multiple servers, so I need to run it as %system Variable%, rather than making a drive letter call, since not every server will have the same drive letter. This is what I have:
If My.Computer.FileSystem.DirectoryExists("D:\backup") Then
This code will work, as I define the drive
If My.Computer.FileSystem.DirectoryExists("%BCK_DRV%\backup") Then
This will not, I get my else error when running it. The %BCK_DRV% is defined in the environment variables, and I can navigate to the folder without issue using %BCK_DRV%\backup. Is there a special way to set and define a %drive% in C#?
Environment.GetEnvironmentVariable?
Code sample:
Dim backupDrive As String = Environment.GetEnvironmentVariable("BCK_DRV") & "\backup"
If My.Computer.FileSystem.DirectoryExists(backupDrive) Then
Try Environment.ExpandEnvironmentVariables():
string raw = #"%BCK_DRV%\backup" ;
string expanded = Environment.ExpandEnvironmentVariables( path_raw ) ;
Naturally, it's up to you to ensure that your process inherits the correct environment.
To expand "%BCK_DRV%\backup" to it's real value you need
Environment.ExpandEnvironmentVariables();
Example:
Environment.ExpandEnvironmentVariables("%winDir%\test")
will expand to "C:\Windows\test" (on my system).

Applying SSIS Package Configuration to multiple packages

I have about 85 SSIS packages that are using the same connection manager.
I understand that each package has its own connection manager.
I am trying to decide what would be the best configurations approach to simply set the connectionstring of the connection manager based on the server the packages are residing on.
I have visited all kinds of suggestions online, but cannot find anywhere the practice where I can simply copy the configuration from one package to the rest of the packages.
There are obviously many approaches such as XML file, SQL Server, Environment Variable, etc.
All the articles out there are pointing to use an Indirect method by using XML or SQL approach. Why would using an environment variable for just holding a connection string is such a bad approach?
Any suggestions are highly appreciated.
Thanks!
Why would using an environment variable for just holding a connection string is such a bad approach?
I find the environment variable or registry key configuration approach to be severely limited by the fact that it can only configure one item at a time. For a connection string, you'd need to define an environment variable for each catalog on a given server. Maybe it's only 2 or 3 and that's manageable. We had a good 30+ per database instance and we had multi-instanced machines so you can see how quickly this problem explodes into a maintenance nightmare. Contrast that with a table or xml based approach which can hold multiple configuration items for a given configuration key.
...best configurations approach to simply set the connectionstring of the connection manager based on the server the packages are residing on.
If you go this route, I'd propose creating a variable, ConnectionString and using it to configure the property. It's an extra step but again I find it's easier to debug a complex expression on a variable versus a complex expression on a property. With a variable, you can always pop a breakpoint on the package and look at the locals window to see the current value.
After creating a variable named ConnectionString, I right click on it, select Properties and set EvaluateAsExpression equal to True and the Expression property to something like "Data Source="+ #[System::MachineName] +"\\DEV2012;Initial Catalog=FOO;Provider=SQLNCLI11.1;Integrated Security=SSPI;"
When that is evaluated, it'd fill in the current machine's name (DEVSQLA) and I'd have a valid OLE DB connection string that connects to a named instance DEV2012.
Data Source=DEVSQLA\DEV2012;Initial Catalog=FOO;Provider=SQLNCLI11.1;Integrated Security=SSPI;
If you have more complex configuration needs than just the one variable, then I could see you using this to configure a connection manager to a sql table that holds the full repository of all the configuration keys and values.
...cannot find anywhere the practice where I can simply copy the configuration from one package to the rest of the packages
I'd go about modifying all 80something packages through a programmatic route. We received a passel of packages from a third party and they had not followed our procedures for configuration and logging. The code wasn't terribly hard and if you describe exactly the types of changes you'd make to solve your need, I'd be happy to toss some code onto this answer. It could be as simple as the following. After calling the function, it will modify a package by adding a sql server configuration on the SSISDB ole connection manager to a table called dbo.sysdtsconfig for a filter named Default.2008.Sales.
string currentPackage = #"C:\Src\Package1.dtsx"
public static void CleanUpPackages(string currentPackage)
{
p = new Package();
p.app.LoadPackage(currentPackage, null);
Configuration c = null;
// Apply configuration Default.2008.Sales
// ConfigurationString => "SSISDB";"[dbo].[sysdtsconfig]";"Default.2008.Sales"
// Name => MyConfiguration
c = p.Configurations.Add();
c.Name = "SalesConfiguration";
c.ConfigurationType = DTSConfigurationType.SqlServer;
c.ConfigurationString = #"""SSISDB"";""[dbo].[sysdtsconfig]"";""Default.2008.Sales""";
app.SaveToXml(sourcePackage, p, null);
}
Adding a variable in to the packages would not take much more code. Inside the cleanup proc, add code like this to add a new variable into your package that has an expression like the above.
string variableName = string.Empty;
bool readOnly = false;
string nameSpace = "User";
string variableValue = string.Empty;
string literalExpression = string.Empty;
variableName = "ConnectionString";
literalExpression = #"""Data Source=""+ #[System::MachineName] +""\\DEV2012;Initial Catalog=FOO;Provider=SQLNCLI11.1;Integrated Security=SSPI;""";
p.Variables.Add(variableName, readOnly, nameSpace, variableValue);
p.Variables[variableName].EvaluateAsExpression = true;
p.Variables[variableName].Expression = literalExpression;
Let me know if I missed anything or you'd like clarification on any points.

SQL Server 2005 CLR function System.NullReferenceException: Object reference not set to an instance of an object

My coworker wrote a package in VB.NET to manipulate strings. I have been asked to implement them through CLR. The package accesses a reference database on the same server as the CLR dll file deployed to standardize the strings. I imported the package to my CLR code to create the functions for SQL Server.
After I deploy the dll file to sql server, the functions work fine except occasionally I get the error
System.NullReferenceException: Object reference not set to an instance of an object.
I have to execute my query several times to make it work. It seems the table is locked or sleeping. My query is like
SELECT EMAIL_ADDRESS, dbo.ufn_getEmailDomain(Email_Address) AS EDOMAIN FROM CONTACT_TEMP
WHERE Email_Address IS NOT NULL AND Email_Address<>''
dbo.ufn_getEmailDomain is the CLR function.
There is no online access to this server at all. I searched for a while and couldn't find why this error comes up occasionally or how to fix it.
Your feedback is greatly appreciated.
my CLR functions here.
<Microsoft.SqlServer.Server.SqlFunction(DataAccess:=DataAccessKind.Read)> _
Public Shared Function ufn_getEmailDomainSLD(ByVal email As String) As String
If email Is Nothing Then
Return Nothing
End If
Dim de As New DataEmail(email)
Dim dm As New DataDomain
Dim emailDomain As String
dm = de.Domain
emailDomain = dm.SLD
Return emailDomain
End Function
If I understood right - function returns domain name from email string.
Try to get it in such a way (if there are not milti-mail string values)
SELECT
EMAIL_ADDRESS,
SUBSTRING(EMAIL_ADDRESS, CHARINDEX('#', Item)+1, 2147483647) AS EDOMAIN
FROM CONTACT_TEMP
WHERE Email_Address IS NOT NULL AND Email_Address<>''
and - find your bug in your clr code. Try to recreate function with option RETURNS NULL ON NULL INPUT. If it is not help - then you need to review and to clean your CLR code.
I found the reason eventually. In the connection string in the CLR code, I should set ENLIST=FALSE because it connects to a different database. Once I set ENLIST=FALSE, the problem seems to be fixed.

DB Query no longer recognizes SQL parameters in existing application when debugging in VS2010

I just started working with an application that I inherited from someone else and I'm having some issues. The application is written in C# and runs in VS2010 against the 3.5 framework. I can't run the application on my machine to debug because it will not recognize the way they referenced their parameters when writing their DB queries.
For instance wherever they have a SQL or DB2 query it is written like this:
using (SqlCommand command = new SqlCommand(
"SELECT Field1 FROM Table1 WHERE FieldID=#FieldID", SQLconnection))
{
command.Parameters.AddWithValue("FieldID", 10000);
SqlDataReader reader = command.ExecuteReader();
...
If you will notice the "parameters.AddWithValue("FieldID", 10000);" statement does not include the "#" symbol from the original command text. When I run it on my machine I get an error message stating that the parameter "FieldID" could not be found.
I change this line:
command.Parameters.AddWithValue("FieldID", 10000);
To this:
command.Parameters.AddWithValue("#FieldID", 10000);
And all is well... until it hits the next SQL call and bombs out with the same error. Obviously this must be a setting within visual studio, but I can't find anything about it on the internet. Half the examples for SQL parameter addition are written including the "#" and the other half do not include it. Most likely I just don't know what to search for.
Last choice is to change every query over to use the "#" at the front of the parameter name, but this is the transportation and operations application used to manage the corporation's shipments and literally has thousands of parameters. Hard to explain the ROI on your project when the answer to the director's question "How's progress?" happens to be "I've been hard at it for a week and I've almost started."
Has anyone run into this problem, or do you know how to turn this setting off so it can resolve the parameter names without the "#"?
Success! System.Data is automatically imported whenever you create a .NET solution. I removed this reference and added it back to make sure that I had the latest version of this library and that fixed the issue. I must have had an old version of this library that was originally pulled in... only thing I can figure.
Its handled by the .NET Framework data providers not Visual Studio.
It depends on the data source. Look here:Working with Parameter Placeholders
You can try working with System.Data.Odbc provider and using the question mark (?) place holder. In thios case dont forget to add the parameters in the same order they are in the query.