开发者

Executing SQL from Script Component + SSIS

开发者 https://www.devze.com 2022-12-20 04:07 出处:网络
Am trying to execute sql from script component, but getting error when trying to establish SQL connection.My Code below in Script Component under PreExecute()

Am trying to execute sql from script component, but getting error when trying to establish SQL connection. My Code below in Script Component under PreExecute()

base.PreExecute();
    variables = null;
    VariableDispenser.LockForWrite("User::TableName");
    VariableDispenser.LockForWrite("User::SqlConnectionString");
    VariableDispenser.GetVariables(out variables);
    tableName = variables[0].Value.ToString();
    sqlConnection = variables[1].Value.ToString();

    dt = new DataTable();

    //sqlConnection = Data Source=LOCALHOST;Initial Catalog=MergeTestDestination;Integrated Security=True;
    using (SqlConnection cnn = new SqlConnection(sqlConnection))
    {
        try
        {
            cnn.Open();
            MessageBox.Show("We are connected.....");
            cnn.Close();
        }
        catch(Exception ex)
        {
            MessageBox.开发者_C百科Show(ex.Message);
        }
    }

Error:

at System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) at System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(String connectionString, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) at System.Data.SqlClient.SqlConnection.ConnectionString_Set(String value) at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) at System.Data.SqlClient.SqlConnection..ctor(String connectionString) at ScriptMain.PreExecute() at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.PreExecute()

what am i doing wrong ? Any help ?

Thanks


Put the following code before the connection constructor Debug.Assert(!string.IsNullOrEmpty(sqlConnection));

0

精彩评论

暂无评论...
验证码 换一张
取 消