I have 2 tables on my Database, one called Sales.Salesperson which is the source, and the target database is dbo.Salesperson. I made a BIML that uses C# code to get a list of existing tables from the source, then import all the data from source to target, for my example, i just have the 1 table, which i listed above. On the C#, i am using SQL connection and SQL command to get the table and schema of all the tables (again only 1 so it can be dynamic),
THE PROBLEM, because i have a period, to sepearte schema and table, in my SQLcommand, when i go from BIML to Generate SSIS package, it gives me an error message from SSIS step EXECUTESQL DirectInput, when i try and truncate table <#=table #> error says "Sales.SalesPerson in package DynamicDataLoad includes invalid characters (/:[].=) for SSIS. the invalid characters will be replaced with_" AND BECAUSE OF THIS, i get an error on my SSIS package
Here is the Code below to help:
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<Packages>
<Package Name="DynamicDataLoad" ConstraintMode ="Linear" ProtectionLevel="DontSaveSensitive">
<Tasks>
<# foreach(var table in GetTables()) { #>
<ExecuteSQL Name="Truncate Table Dest <#=table#>" ConnectionName="Target">
**<DirectInput>Truncate Table <#=table#></DirectInput>
</ExecuteSQL>**
<Dataflow Name="Load Table <#=table#>" >
<Transformations>
<OleDbSource Name="Source Table" ConnectionName="Source">
<ExternalTableInput Table="<#=table#>" />
</OleDbSource>
<OleDbDestination Name="Destination Table" ConnectionName="Target">
<ExternalTableOutput Table="<#=table#>" />
</OleDbDestination>
</Transformations>
</Dataflow>
<# } #>
</Tasks>
</Package>
</Packages>
</Biml>
and below is the C# part, if you look at the SQLcommand, i am bringing back Schema then table in a list called "table, which gets used in the above BIML to list all tables to be converted into SSIS package, this is used in the BIML part called truncation, which is where the error is coming from in the BIML.
<#+
List<string> GetTables() {
List<string> tables = new List<string>();
SqlConnection cn = new SqlConnection("Data Source=mdsdqsdev;Initial Catalog=Test;Persist Security Info=False;Integrated Security=SSPI;");
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
string q = "Select TABLE_SCHEMA+'.'+TABLE_NAME as name from INFORMATION_SCHEMA.TABLES";
var cmd = new SqlCommand(q);
cmd.Connection = cn;
try
{
da.SelectCommand = cmd;
ds.Tables.Add(new DataTable("Results"));
if(cn.State != ConnectionState.Open)
{
cn.Open();
}
ds.Tables[0].BeginLoadData();
da.Fill(ds,"Results");
ds.Tables[0].EndLoadData();
dt = ds.Tables[0];
if(cn.State != ConnectionState.Closed)
{
cn.Close();
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (cn.State != ConnectionState.Closed)
{
cn.Close();
}
cn.Dispose();
}
foreach (DataRow row in dt.Rows)
{
tables.Add(row["name"].ToString());
}
return tables;
}
#>