conditional logic in BIML

时光怂恿深爱的人放手 提交于 2019-12-13 20:48:04

问题


Conditional logic not working on my query.

So referring to the above query I have a unique constraint on the table checks for same values of version and revision number it errors out id the values are same this is good but I have to write a conditional logic saying that whenever there is a error message in the varaible ex.Message then the code should not execute and ask for reloading of package.I have a problem in my conditional logic saying that it couldn't find ex.Message how do i make it work.

<#@ import namespace="System.Data" #>    
<#@ import namespace="System" #>
<#@ import namespace="System.Windows.Forms" #>

 <#@ assembly name= 
 "C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Windows.Forms.dll" 
#>

<#
    var ErrorMessage = ex.Message;
    if (ErrorMessage == null)
     {


               var timeout = 3600;
               var is_sharded = (src_db=="online"||src_db=="launch")? 1 : 
                    0;
                var is_boss_foxpro_src = (src_db=="boss_foxpro")? 1: 0;

               var connector_type = (is_boss_foxpro_src == 1)? "_ole":"";

               var src_type = (is_boss_foxpro_src == 1)? 
        "OleDb":"AdoNet";

       var parallel_threads = 1;

         var enable_package_configurations = 1;

    switch(src_db)
   {
    case "online":
        parallel_threads = 10;
        break;
    case "launch":
        parallel_threads = 2;
        break;
    case "boss_foxpro":
        parallel_threads = 11;
        break;
    default:
        parallel_threads = 1;
        break;
}


var shard_filter = (is_sharded == 1 || is_boss_foxpro_src == 1)  ? "WHERE 
  shard_id =\" + (DT_STR, 10, 1252) @[User::shard_id] + \"":"";
}
else
  {
   MessageBox.Show("String is not empty or null");
   }
#>
<Packages>
    <
       -- ETL code here
    >

<# try {

string queryString = "INSERT INTO [audit].Biml_Expansions( DBName, SchemaName, TableName, PackageName, ExpansionType, VersionNumber, RevisionNumber ) VALUES (@DBName, @SchemaName, @TableName, @PackageName, @ExpansionType, @VersionNumber, @RevisionNumber)";
string connectionString = "Server=HQ-DEV-SQLDW01;Database=IM_STAGE;Integrated Security=True;";

  System.Data.SqlClient.SqlConnection connection = new 
  System.Data.SqlClient.SqlConnection(connectionString);
  System.Data.SqlClient.SqlCommand command = new 
System.Data.SqlClient.SqlCommand(queryString, connection);
connection.Open();
System.Data.SqlClient.SqlParameter DBName  = new 
        System.Data.SqlClient.SqlParameter();
        DBName.ParameterName = "@DBName";
        DBName.Value         = tgt_db;
        System.Data.SqlClient.SqlParameter SchemaName  = new 
        System.Data.SqlClient.SqlParameter();
        SchemaName.ParameterName = "@SchemaName";
        SchemaName.Value         = tgt_schema;
        System.Data.SqlClient.SqlParameter TableName  = new 
        System.Data.SqlClient.SqlParameter();
        TableName.ParameterName = "@TableName";
        TableName.Value         = tgt_table;
        System.Data.SqlClient.SqlParameter PackageName  = new 
        System.Data.SqlClient.SqlParameter();
        PackageName.ParameterName = "@PackageName";
        PackageName.Value        = "pkg_"+tgt_schema+"_"+tgt_table+".dtsx";
         System.Data.SqlClient.SqlParameter ExpansionType  = new 
        System.Data.SqlClient.SqlParameter();
        ExpansionType.ParameterName = "@ExpansionType";
        ExpansionType.Value         = "Load";
        System.Data.SqlClient.SqlParameter VersionNumber  = new 
        System.Data.SqlClient.SqlParameter();
        VersionNumber.ParameterName = "@VersionNumber";
        VersionNumber.Value         = version_num;
        System.Data.SqlClient.SqlParameter RevisionNumber  = new 
        System.Data.SqlClient.SqlParameter();
        RevisionNumber.ParameterName = "@RevisionNumber";
        RevisionNumber.Value         = revision_num;

command.Parameters.Add(DBName);
command.Parameters.Add(SchemaName);
command.Parameters.Add(TableName);
command.Parameters.Add(PackageName);
command.Parameters.Add(ExpansionType);
command.Parameters.Add(VersionNumber);
command.Parameters.Add(RevisionNumber);
command.ExecuteNonQuery();

}

catch(Exception ex)
{
  MessageBox.Show( "Error: " + ex.Message);
 }





The name ex doesn't exist in the current context

来源:https://stackoverflow.com/questions/56907452/conditional-logic-in-biml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!