How to execute stored procedure on ODBC Snowflake Destinastion?

徘徊边缘 提交于 2019-12-13 03:58:20

问题


I'am building new package for move data from aws sql server instance to snowflake odbc destination. If i found rows which was updated i must change them on snowflake as well. In common's i found only 'OLE DB Command' for execute procedure for update diffrent rows.

The problem is i need something like "ODBC Command" for execute procedure to update diffrent rows between SQL Server&Snowflake.


回答1:


OK, I do it.

So if u need UPDATE rows on ODBC destination in SSIS u have only one way to do that u need to use Script Component. Before I thought it will be something like ODBC Command and we will need to write stored procedure to change rows in the destination. I link that for ppl who care in the future.

The OLE DB Command transformation runs an SQL statement for each row in a data flow. For example, you can run an SQL statement that inserts, updates, or deletes rows in a database table. Microsoft OLE DB Command description

I wrote a simple code in c# to Update Rows and it works perfectly. U can simple rebuild it for execute procedure or do whatever u need.

public class ScriptMain : UserComponent
 {
  OdbcConnection odbcConn;
  OdbcCommand odbcCmd;
  OdbcParameter odbcParam;

public override void AcquireConnections(object Transaction)
  {
    /// Create a String base on that which u define on package for connection and 
        adding a password

    string connectionString;
    connectionString = this.Connections.SFConnection.ConnectionString;
    odbcConn = new OdbcConnection(connectionString + "PWD=YOURPASSWORD");
    odbcConn.Open();
    }

public override void PreExecute()
{
    ///Create command which we wanna execute

    base.PreExecute();
    odbcCmd = new OdbcCommand("UPDATE klienci SET IMIE= ?,NAZWISKO= ? ,NUMER_TELEFONU= ? ,EMAIL= ? ,ULICA= ? ,MIASTO= ? ,STATE= ? ,ZIP_CODE = ? WHERE CUSTOMER_ID= ?", odbcConn);

}

public override void Input0_ProcessInputRow(Input0Buffer Row)
    {
      ///Adding parameters and connecting them with our input column from package

    odbcCmd.Parameters.AddWithValue("@IMIE", Row.Sourcefirstname);
    odbcCmd.Parameters.AddWithValue("@NAZWISKO", Row.Sourcelastname);
    odbcCmd.Parameters.AddWithValue("@NUMER_TELEFONU", Row.Sourcephone);
    odbcCmd.Parameters.AddWithValue("@EMAIL", Row.Sourceemail);
    odbcCmd.Parameters.AddWithValue("@ULICA", Row.Sourcestreet);
    odbcCmd.Parameters.AddWithValue("@MIASTO", Row.Sourcecity);
    odbcCmd.Parameters.AddWithValue("@STATE", Row.Sourcestate);
    odbcCmd.Parameters.AddWithValue("@ZIP_CODE", Row.Sourcezipcode);
    odbcCmd.Parameters.AddWithValue("@CUSTOMER_ID", Row.Sourcecustomerid);
    odbcCmd.ExecuteNonQuery();

    }
}


来源:https://stackoverflow.com/questions/56144342/how-to-execute-stored-procedure-on-odbc-snowflake-destinastion

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