SSIS中的C#Script中引发了异常

时间:2014-04-21 09:09:45

标签: c# visual-studio-2010 ssis

我正在参加SSIS 2010,以便将我的项目从我的电脑转移到服务器 但是我遇到了C#Script任务的问题,它在我的电脑上工作得非常好,但是在服务器中它给了我一个错误。

执行脚本时出现此错误

enter image description here

这就是C#脚本:

#region Help:  Introduction to the script task
#endregion
#region Namespaces
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System;// Basic Import Statement
using System.Collections.Generic; // Allows Us To Use Lists
using System.IO; // For File handles
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
#endregion
namespace ST_c47c0258ca4d4851b04d0fdb997749b9
{
    [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    {
        #region Help:  Using Integration Services variables and parameters in a script
        #endregion
        #region Help:  Firing Integration Services events from a script
        #endregion
        #region Help:  Using Integration Services connection managers in a script
        #endregion
        public void Main()
        {
            string inFolderName = @"\\SERVER\DWH File\SocialMedia\Source\Facebook\";
            string outFolderName = @"\\SERVER\DWH File\SocialMedia\Final Source\Facebook\";
            List<string> lines = new List<string>();
            string line;
            DirectoryInfo folder = new DirectoryInfo(inFolderName);//Assuming Test is your Folder
            FileInfo[] Files = folder.GetFiles("*.csv"); //Getting Text files

            using (var file = new System.IO.StreamReader(outFolderName + "Facebook Insights.csv"))
            {
                while ((line = file.ReadLine()) != null)
                {

                    lines.Add(line);

                }

            }
            foreach (FileInfo f in Files)
            {

                using (var file = new System.IO.StreamReader(f.FullName))
                {
                    while ((line = file.ReadLine()) != null)
                    {
                        if (line.Length == 0 || line.Contains("#") || line.ToLower().Contains("date") || line.ToLower().Contains("screen"))
                        {
                            continue;
                        }
                        else
                        {
                            lines.Add(line);
                        }
                    }
                    //System.IO.File.WriteAllLines(outFolderName + "TwtMentions.csv", lines.ToArray());
                }

                System.IO.File.WriteAllLines(outFolderName + "Facebook Insights.csv", lines.ToArray());
                File.Delete(f.FullName);
            }
            Dts.TaskResult = (int)ScriptResults.Success;
        }
        #region ScriptResults declaration
        enum ScriptResults
        {
            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
        };
        #endregion
    }
}

我的问题问题在哪里

1 个答案:

答案 0 :(得分:0)

我感觉它可能是你的文件夹URI。当一个包在您的用户ID下运行时,它会使用您的权限,但是当从sql代理运行时,您必须确保它在正确的权限下运行,以便允许它访问该网络位置。

见:

http://bi-polar23.blogspot.com/2007/12/ssis-and-sql-server-agent.html