SSIS:如何通过脚本任务设置初始目录的值

发布于 2024-12-03 14:33:49 字数 545 浏览 0 评论 0原文

我正在循环连接:

for (int x = 0; x < Dts.Connections.Count; x++)
{

    switch (Dts.Connections[x].Name.ToString())
    {
        case "m":

           for (int z = 0; z < Dts.Connections[x].Properties.Count; z++)
            {
                      if ( Dts.Connections[x].Properties[n].Name = "Initial Catalog"){
                Dts.Connections[x].Properties[n].SetValue(object o, object value);}
            }

            break;
    }                  
}

上面是我所得到的,setvalue 的签名是 (Object o, Object value)

i am looping through my connections:

for (int x = 0; x < Dts.Connections.Count; x++)
{

    switch (Dts.Connections[x].Name.ToString())
    {
        case "m":

           for (int z = 0; z < Dts.Connections[x].Properties.Count; z++)
            {
                      if ( Dts.Connections[x].Properties[n].Name = "Initial Catalog"){
                Dts.Connections[x].Properties[n].SetValue(object o, object value);}
            }

            break;
    }                  
}

above is as far as i have gotten, the signature of setvalue is (Object o, Object value)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

樱花落人离去 2024-12-10 14:33:49

根据 SetValue 的文档(),第一个参数是要设置属性的对象,第二个参数是属性值。所以它应该是这样的:

for (int i = 0; i < Dts.Connections.Count; i++)
{
    var connection = Dts.Connections[i];
    if (connection.Name == "m")
    {
        for (int j = 0; j < connection.Properties.Count; j++)
        {
            var property = connection.Properties[j];

            if (property.Name == "Initial Catalog")
                property.SetValue(connection, "some value");
        }
    }
}

或者使用 LINQ:(

var connection = Dts.Connections.Cast<ConnectionManager>()
                                .First(cm => cm.Name == "m");
var property = connection.Properties.Cast<DtsProperty>()
                                    .Single(p => p.Name == "Initial Catalog");
property.SetValue(connection, "some value");

Cast() 是必要的,因为遗憾的是,这些集合不是通用的。)

According to the documentation of SetValue(), the first parameter is the object on which you want to set the property and the second is the property value. So it should be something like this:

for (int i = 0; i < Dts.Connections.Count; i++)
{
    var connection = Dts.Connections[i];
    if (connection.Name == "m")
    {
        for (int j = 0; j < connection.Properties.Count; j++)
        {
            var property = connection.Properties[j];

            if (property.Name == "Initial Catalog")
                property.SetValue(connection, "some value");
        }
    }
}

Or with LINQ:

var connection = Dts.Connections.Cast<ConnectionManager>()
                                .First(cm => cm.Name == "m");
var property = connection.Properties.Cast<DtsProperty>()
                                    .Single(p => p.Name == "Initial Catalog");
property.SetValue(connection, "some value");

(The Cast()s are necessary, because the collections are, sadly, not generic.)

一袭水袖舞倾城 2024-12-10 14:33:49

尝试使用以下命令设置 DTS 连接

ConnectionManager cn = Dts.Connections.Add("OLEDB");
cn.ConnectionString = "Data Source=localhost;Initial Catalog=AdventureWorks;Provider=SQLNCLI10;Integrated Security=SSPI;Auto Translate=False;";

Try using the following to setup a DTS Connection

ConnectionManager cn = Dts.Connections.Add("OLEDB");
cn.ConnectionString = "Data Source=localhost;Initial Catalog=AdventureWorks;Provider=SQLNCLI10;Integrated Security=SSPI;Auto Translate=False;";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文