Skip to content

Commit

Permalink
2014 updates, adding ability to use ADO.NET connections from SQLCommands
Browse files Browse the repository at this point in the history
  • Loading branch information
johnwelch committed Apr 15, 2014
1 parent cbcec77 commit 54adf40
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 45 deletions.
2 changes: 1 addition & 1 deletion SsisUnit/Commands/ComponentInputCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

using SsisUnit.TestComponents;

#if SQL2012 || SQL2008
#if SQL2014 || SQL2012 || SQL2008
using IDTSComponentMetaData = Microsoft.SqlServer.Dts.Pipeline.Wrapper.IDTSComponentMetaData100;
using IDTSInput = Microsoft.SqlServer.Dts.Pipeline.Wrapper.IDTSInput100;
#elif SQL2005
Expand Down
2 changes: 1 addition & 1 deletion SsisUnit/Commands/ComponentOutputCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime;

#if SQL2012 || SQL2008
#if SQL2014 || SQL2012 || SQL2008
using IDTSComponentMetaData = Microsoft.SqlServer.Dts.Pipeline.Wrapper.IDTSComponentMetaData100;
using IDTSOutput = Microsoft.SqlServer.Dts.Pipeline.Wrapper.IDTSOutput100;
#elif SQL2005
Expand Down
9 changes: 9 additions & 0 deletions SsisUnit/ConnectionRef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ public ConnectionRef(XmlNode connectionRef)
[Description("Connection String used by SQL Commands or the name of a ConnectionManager in the package"),
Editor("SsisUnit.Design.ConnectionStringEditor, SsisUnit.Design.2012, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6fbed22cbef36cab", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"),
ReadOnly(false)]
#elif SQL2014
[Description("Connection String used by SQL Commands or the name of a ConnectionManager in the package"),
Editor("SsisUnit.Design.ConnectionStringEditor, SsisUnit.Design.2014, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6fbed22cbef36cab", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"),
ReadOnly(false)]
#endif

public string ConnectionString { get; set; }

[Description("The name that a SQLCommand will use to reference this connection"),
Expand Down Expand Up @@ -74,6 +79,10 @@ public ConnectionTypeEnum ConnectionType
[Description("The invariant name of the ADO.NET provider to use when ConnectionType == AdoNet."),
TypeConverter("SsisUnit.Design.ConnectionRefInvariantTypeConverter, SsisUnit.Design.2012, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6fbed22cbef36cab"),
ReadOnly(false)]
#elif SQL2014
[Description("The invariant name of the ADO.NET provider to use when ConnectionType == AdoNet."),
TypeConverter("SsisUnit.Design.ConnectionRefInvariantTypeConverter, SsisUnit.Design.2014, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6fbed22cbef36cab"),
ReadOnly(false)]
#endif
public string InvariantType { get; set; }

Expand Down
24 changes: 17 additions & 7 deletions SsisUnit/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

using SsisUnit.Enums;

#if SQL2012
#if SQL2014 || SQL2012
using System.Linq;
using System.Data.SqlClient;

using Microsoft.SqlServer.Management.IntegrationServices;
#endif

#if SQL2012 || SQL2008
#if SQL2014 || SQL2012 || SQL2008
using IDTSComponentMetaData = Microsoft.SqlServer.Dts.Pipeline.Wrapper.IDTSComponentMetaData100;
using IDTSInput = Microsoft.SqlServer.Dts.Pipeline.Wrapper.IDTSInput100;
using IDTSOutput = Microsoft.SqlServer.Dts.Pipeline.Wrapper.IDTSOutput100;
Expand Down Expand Up @@ -279,7 +279,7 @@ public static Package LoadPackage(SsisTestSuite testSuite, string packageName, S
}
finally
{
#if SQL2012
#if SQL2014 || SQL2012
Project project = loadedProject as Project;

if (project != null)
Expand Down Expand Up @@ -367,7 +367,7 @@ public static Package LoadPackage(SsisTestSuite testSuite, string packageName, S
switch (packageRef.StorageType)
{
case PackageStorageType.FileSystem:
#if SQL2012
#if SQL2014 || SQL2012
Project project;

if (string.IsNullOrWhiteSpace(packageRef.ProjectPath))
Expand Down Expand Up @@ -395,7 +395,7 @@ public static Package LoadPackage(SsisTestSuite testSuite, string packageName, S
package = ssisApp.LoadFromDtsServer(packageRef.PackagePath, packageRef.Server, null);
break;
case PackageStorageType.SsisCatalog:
#if SQL2012
#if SQL2014 || SQL2012
password = packageRef.StoredPassword == null ? null : packageRef.StoredPassword.ConvertToUnsecureString();

SqlConnectionStringBuilder sqlConnectionStringBuilder = new SqlConnectionStringBuilder { DataSource = packageRef.Server, InitialCatalog = "SSISDB", IntegratedSecurity = true };
Expand Down Expand Up @@ -448,6 +448,8 @@ public static Package LoadPackage(SsisTestSuite testSuite, string packageName, S
const string SsisPackageStoreVersion = "2008";
#elif SQL2012
const string SsisPackageStoreVersion = "2012";
#elif SQL2014
const string SsisPackageStoreVersion = "2014";
#endif

if (packageRef != null && packageRef.StorageType == PackageStorageType.PackageStore && dtsEx.ErrorCode == HResults.DTS_E_PACKAGENOTFOUND)
Expand Down Expand Up @@ -483,7 +485,7 @@ private static void ParseSsisProjectPath(string relativeProjectPath, out string
ssisProjectName = relativeProjectPath.Substring(indx + 1 > relativeProjectPath.Length ? indx : indx + 1);
}

#if SQL2012
#if SQL2014 || SQL2012
private static Package LoadPackageFromProject(Project loadedProject, string projectName, string packageName)
{
PackageItem packageItem = loadedProject.PackageItems.FirstOrDefault(x => string.Compare(x.StreamName, packageName, StringComparison.InvariantCultureIgnoreCase) == 0);
Expand Down Expand Up @@ -586,7 +588,7 @@ internal static DbProviderFactory GetReservedFactory(string providerType)

internal static DbCommand GetCommand(ConnectionRef connectionRef, string commandText)
{
DbProviderFactory dbFactory = connectionRef.ConnectionType != ConnectionRef.ConnectionTypeEnum.AdoNet ? GetReservedFactory(connectionRef.ConnectionString) : GetFactory(connectionRef.InvariantType);
var dbFactory = CreateProviderFactory(connectionRef);

DbConnection conn = dbFactory.CreateConnection();

Expand All @@ -606,6 +608,14 @@ internal static DbCommand GetCommand(ConnectionRef connectionRef, string command
return dbCommand;
}

internal static DbProviderFactory CreateProviderFactory(ConnectionRef connectionRef)
{
DbProviderFactory dbFactory = connectionRef.ConnectionType != ConnectionRef.ConnectionTypeEnum.AdoNet
? GetReservedFactory(connectionRef.ConnectionString)
: GetFactory(connectionRef.InvariantType);
return dbFactory;
}

public static IDTSOutput FindComponentOutput(MainPipe mainPipe, string path)
{
if (mainPipe == null)
Expand Down
1 change: 1 addition & 0 deletions SsisUnit/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@
[assembly: InternalsVisibleTo("SsisUnit2008.Design, PublicKey=0024000004800000940000000602000000240000525341310004000001000100cd0c8c9049e8ae2a4e2665f34aad415e66587e19a343aeb1138671262a9f4eee33296545920a87dfd785ed54df26d766634eefd55633e11ae91b501962c69cb227f56ccd450486356ad3a8f854f8037e5a37eb3d674fff96bfc2c1d9f30d1e17570a9dc96b53e1c49da433fa381b9d00e6be0536aae4612e76400862e5127298")]
#elif SQL2012
[assembly: InternalsVisibleTo("SsisUnit.Design.2012, PublicKey=0024000004800000940000000602000000240000525341310004000001000100cd0c8c9049e8ae2a4e2665f34aad415e66587e19a343aeb1138671262a9f4eee33296545920a87dfd785ed54df26d766634eefd55633e11ae91b501962c69cb227f56ccd450486356ad3a8f854f8037e5a37eb3d674fff96bfc2c1d9f30d1e17570a9dc96b53e1c49da433fa381b9d00e6be0536aae4612e76400862e5127298")]
#elif SQL2014
[assembly: InternalsVisibleTo("SsisUnit.Design.2014, PublicKey=0024000004800000940000000602000000240000525341310004000001000100cd0c8c9049e8ae2a4e2665f34aad415e66587e19a343aeb1138671262a9f4eee33296545920a87dfd785ed54df26d766634eefd55633e11ae91b501962c69cb227f56ccd450486356ad3a8f854f8037e5a37eb3d674fff96bfc2c1d9f30d1e17570a9dc96b53e1c49da433fa381b9d00e6be0536aae4612e76400862e5127298")]
#endif
2 changes: 1 addition & 1 deletion SsisUnit/SSISUnit.2014.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;SQL2012</DefineConstants>
<DefineConstants>TRACE;DEBUG;SQL2014</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
Expand Down
74 changes: 40 additions & 34 deletions SsisUnit/SqlCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using SsisUnitBase.Enums;
using SsisUnitBase.EventArgs;

#if SQL2012 || SQL2008
#if SQL2014 || SQL2012 || SQL2008
using IDTSComponentMetaData = Microsoft.SqlServer.Dts.Pipeline.Wrapper.IDTSComponentMetaData100;
#elif SQL2005
using IDTSComponentMetaData = Microsoft.SqlServer.Dts.Pipeline.Wrapper.IDTSComponentMetaData90;
Expand All @@ -23,10 +23,10 @@ public class SqlCommand : CommandBase
private const string PropConnection = "connectionRef";
private const string PropReturnsValue = "returnsValue";

private const string TagOledb = "Provider";
private const string TagSql = "SqlClient";
private const string FactoryOledb = "System.Data.OleDb";
private const string FactorySql = "System.Data.SqlClient";
//private const string TagOledb = "Provider";
//private const string TagSql = "SqlClient";
//private const string FactoryOledb = "System.Data.OleDb";
//private const string FactorySql = "System.Data.SqlClient";

public SqlCommand(SsisTestSuite testSuite)
: base(testSuite)
Expand Down Expand Up @@ -114,7 +114,7 @@ public override object Execute(Package package, DtsContainer container)
result = null;
}

OnCommandCompleted(new CommandCompletedEventArgs(DateTime.Now, CommandName, null, null, string.Format("The {0} command has completed.", CommandName), commandParentType));
OnCommandCompleted(new CommandCompletedEventArgs(DateTime.Now, CommandName, null, null, string.Format(CultureInfo.CurrentCulture, "The {0} command has completed.", CommandName), commandParentType));
}
catch (Exception ex)
{
Expand Down Expand Up @@ -146,8 +146,8 @@ private void InitializeProperties()

private DbCommand GetCommand(ConnectionRef connectionRef, string commandText)
{
DbProviderFactory dbFactory = GetFactory(connectionRef.ConnectionString);

DbProviderFactory dbFactory = Helper.CreateProviderFactory(connectionRef);
DbConnection conn = dbFactory.CreateConnection();

if (conn == null)
Expand All @@ -166,32 +166,32 @@ private DbCommand GetCommand(ConnectionRef connectionRef, string commandText)
return dbCommand;
}

/// <summary>
/// Tries to return the appropriate Provider Factory based on the value passed in. Creating
/// the factory depends on having the appropriate provider name, so this method checks for
/// common values that indicate what type of connection it is.
/// </summary>
/// <param name="providerType">Value that provides a hint on the connection type</param>
/// <returns>A generic provider factory based on the provider type passed in.</returns>
private DbProviderFactory GetFactory(string providerType)
{
string factoryInvariantName;

if (providerType.Contains(TagOledb))
{
factoryInvariantName = FactoryOledb;
}
else if (providerType.Contains(TagSql))
{
factoryInvariantName = FactorySql;
}
else
{
throw new ArgumentException("Connection type not supported");
}

return DbProviderFactories.GetFactory(factoryInvariantName);
}
///// <summary>
///// Tries to return the appropriate Provider Factory based on the value passed in. Creating
///// the factory depends on having the appropriate provider name, so this method checks for
///// common values that indicate what type of connection it is.
///// </summary>
///// <param name="providerType">Value that provides a hint on the connection type</param>
///// <returns>A generic provider factory based on the provider type passed in.</returns>
//private DbProviderFactory GetFactory(string providerType)
//{
// string factoryInvariantName;

// if (providerType.Contains(TagOledb))
// {
// factoryInvariantName = FactoryOledb;
// }
// else if (providerType.Contains(TagSql))
// {
// factoryInvariantName = FactorySql;
// }
// else
// {
// throw new ArgumentException("Connection type not supported");
// }

// return DbProviderFactories.GetFactory(factoryInvariantName);
//}

#if SQL2005
[Description("The Connection that the SQLCommand will use"),
Expand All @@ -202,6 +202,9 @@ private DbProviderFactory GetFactory(string providerType)
#elif SQL2012
[Description("The Connection that the SQLCommand will use"),
TypeConverter("SsisUnit.Design.ConnectionRefConverter, SsisUnit.Design.2012, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6fbed22cbef36cab")]
#elif SQL2014
[Description("The Connection that the SQLCommand will use"),
TypeConverter("SsisUnit.Design.ConnectionRefConverter, SsisUnit.Design.2014, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6fbed22cbef36cab")]
#endif
public ConnectionRef ConnectionReference
{
Expand Down Expand Up @@ -233,6 +236,9 @@ public bool ReturnsValue
#elif SQL2012
[Description("The SQL statement to be executed by the SQLCommand"),
Editor("SsisUnit.Design.QueryEditor, SsisUnit.Design.2012, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6fbed22cbef36cab", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
#elif SQL2014
[Description("The SQL statement to be executed by the SQLCommand"),
Editor("SsisUnit.Design.QueryEditor, SsisUnit.Design.2014, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6fbed22cbef36cab", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
#endif
// ReSharper disable InconsistentNaming
public string SQLStatement
Expand Down
4 changes: 3 additions & 1 deletion SsisUnit/SsisTestSuite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public int SsisVersion
return 2008;
#elif SQL2012
return 2012;
#elif SQL2014
return 2014;
#endif
}
}
Expand Down Expand Up @@ -479,7 +481,7 @@ private static Stream GetStreamFromExecutingAssembly(string resourceName)
Assembly asm = Assembly.GetExecutingAssembly();
#if SQL2005
Stream resource = asm.GetManifestResourceStream(asm.GetName().Name + "." + resourceName);
#elif SQL2008 || SQL2012
#elif SQL2014 || SQL2008 || SQL2012
Stream resource = asm.GetManifestResourceStream("SsisUnit." + resourceName);
#endif
return resource;
Expand Down

0 comments on commit 54adf40

Please sign in to comment.