簡體   English   中英

SSIS當訪問模式為SQL Command時,如何將多個參數映射到oledb源?

[英]SSIS How to map multiple parameters to oledb source when access mode is SQL Command?

**我的Oledb源代碼是-
添加第二個參數時,它會優先覆蓋。 怎么解決?**

    IDTSComponentMetaData100 Source = PopulateEtlDataSourceDetailDFT.ComponentMetaDataCollection.New();
    Source.ComponentClassID = "DTSAdapter.OleDbSource";
    CManagedComponentWrapper srcDesignTime = Source.Instantiate();
    srcDesignTime.ProvideComponentProperties();
    Source.Name = "OLEDB Source";
    //Assigning Connection manager
    Source.RuntimeConnectionCollection[0].ConnectionManagerID = Config.ID;
    Source.RuntimeConnectionCollection[0].ConnectionManager = DtsConvert.GetExtendedInterface(Config);
    // Set the custom properties of the source.
    srcDesignTime.SetComponentProperty("AccessMode", 2);

    Guid variableGuid = new Guid(ETLSourceRunId.ID);
    String ParamProperty = @"""@OrganizationName"",{" + variableGuid.ToString().ToUpper() + @"};";
    srcDesignTime.SetComponentProperty("ParameterMapping", ParamProperty);
    Guid variableGuid1 = new Guid(Parent_ETLSourceRunId.ID);
    String ParamProperty1 = @"""@SourceRunID"",{" + variableGuid.ToString().ToUpper() + @"};";
    srcDesignTime.SetComponentProperty("ParameterMapping", ParamProperty1);       

    srcDesignTime.SetComponentProperty("SqlCommand","EXEC [dbo].[USP_GetCustomerEtlSourceDetailRecordSet] @OrganizationName=?,@SourceRunID=?");        
    srcDesignTime.AcquireConnections(null);
    srcDesignTime.ReinitializeMetaData();
    srcDesignTime.ReleaseConnections();

1.如何向oledb源添加多個參數?
2.如何在oledb源代碼中添加項目參數?

我不是C#的專業人士,但是:

Guid variableGuid = new Guid(ETLSourceRunId.ID);
String ParamProperty = @"""@OrganizationName"",{" + variableGuid.ToString().ToUpper() + @"};";
srcDesignTime.SetComponentProperty("ParameterMapping", ParamProperty);
Guid variableGuid1 = new Guid(Parent_ETLSourceRunId.ID);
String ParamProperty1 = @"""@SourceRunID"",{" + variableGuid.ToString().ToUpper() + @"};";
srcDesignTime.SetComponentProperty("ParameterMapping", ParamProperty1);

從第二行開始:

String ParamProperty1 = @"""@SourceRunID"",{" + variableGuid.ToString().ToUpper() + @"};";

它不應該是variableGuid1.ToString()。Upper()而不是variableGuid.ToString()。Upper(),因為您將值分配為:

Guid variableGuid1 = new Guid(Parent_ETLSourceRunId.ID);

嘗試使用來自變量的SQL命令作為數據訪問模式。 創建一個字符串變量,並將其值設置為SqlCommand。 如果SqlCommand需要多個參數,則再次創建變量以存儲這些值,並在SqlCommand變量值中使用這些變量。

您可以按照文章開始。

腳步

1)為SqlCommand創建變量

strVarSqlCommand = "EXEC [dbo].[USP_GetCustomerEtlSourceDetailRecordSet] @OrganizationName=strVarOrgName ,@SourceRunID=strVarSrcRunId"

2)創建變量以引用Sqlcommand變量

strVarOrgName = "XXX"
strVarSrcRunId="YYY"

根據您的要求,您可以將這些變量的值設置為硬編碼或動態設置。

3)在ole db源中使用strVarSqlCommand變量,其中數據訪問模式是帶有變量的命令

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM