它似乎应该很简单但是我还没有找到一种方法将存储在SSIS字符串变量中的值保存到文本文件中.我已经研究过在数据流中使用平面文件目的地但需要数据流源.
关于如何做到这一点的任何想法?
下面是一些在C#中使用SQL CLR的代码示例.如果你在2005年,我需要使用VB我相信.脚本任务还需要将read变量属性设置为MyVariable,以使变量的值可用.
// create a writer and open the file
TextWriter tw = new StreamWriter("\\\\server\\share$\\myfile.txt");
// write a line of text to the file
tw.WriteLine(Dts.Variables["MyVariable"].Value);
// close the stream
tw.Close();
使用脚本任务.
我刚试过这个.我创建了一个文件连接管理器,连接字符串指向我想写的文件.然后我创建了一个包含要写入的文本的字符串变量.
我添加了一个Script Task,在Read Only Variables列表中指定了我的字符串变量,然后单击Edit Script.脚本如下:
    public void Main()
    {
        ConnectionManager cm = Dts.Connections["File.tmp"];
        var path = cm.ConnectionString;
        var textToWrite = (string)Dts.Variables["User::StringVariable"].Value;
        System.IO.File.WriteAllText(path, textToWrite);
        Dts.TaskResult = (int)ScriptResults.Success;
    }
这没有问题.