SSIS中的C#脚本中引发了异常

SSIS中的C#脚本中引发了异常,c#,visual-studio-2010,ssis,C#,Visual Studio 2010,Ssis,我在SSIS 2010中为我的项目从pc到服务器进行转换 但是我在C#Script任务上遇到了一个问题,它在我的pc上运行得很好,但在服务器上却给了我一个错误 执行脚本时出现此错误 这就是C#脚本: #区域帮助:脚本任务简介 #端区 #区域名称空间 使用制度; 使用System.Collections.Generic; 使用System.Linq; 使用System.Web; 使用系统;//基本进口报表 使用System.Collections.Generic;//允许我们使用列表 使用Sys

我在SSIS 2010中为我的项目从pc到服务器进行转换 但是我在C#Script任务上遇到了一个问题,它在我的pc上运行得很好,但在服务器上却给了我一个错误

执行脚本时出现此错误

这就是C#脚本:

#区域帮助:脚本任务简介
#端区
#区域名称空间
使用制度;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用系统;//基本进口报表
使用System.Collections.Generic;//允许我们使用列表
使用System.IO;//用于文件句柄
使用系统数据;
使用Microsoft.SqlServer.Dts.Runtime;
使用System.Windows.Forms;
#端区
名称空间ST_c47c0258ca4d4851b04d0fdb997749b9
{
[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
公共部分类ScriptMain:Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
#区域帮助:在脚本中使用Integration Services变量和参数
#端区
#区域帮助:从脚本触发Integration Services事件
#端区
#区域帮助:在脚本中使用Integration Services连接管理器
#端区
公共图书馆
{
字符串inFolderName=@“\\SERVER\DWH File\SocialMedia\Source\Facebook\”;
字符串outFolderName=@“\\SERVER\DWH File\SocialMedia\Final Source\Facebook\”;
列表行=新列表();
弦线;
DirectoryInfo folder=newdirectoryinfo(inFolderName);//假设Test是您的文件夹
FileInfo[]Files=folder.GetFiles(“*.csv”);//获取文本文件
使用(var file=new System.IO.StreamReader(outFolderName+“Facebook Insights.csv”))
{
而((line=file.ReadLine())!=null)
{
行。添加(行);
}
}
foreach(文件中的文件信息)
{
使用(var file=new System.IO.StreamReader(f.FullName))
{
而((line=file.ReadLine())!=null)
{
如果(line.Length==0 | | line.Contains(“#”)| | line.ToLower()包含(“日期”)| | line.ToLower()包含(“屏幕”))
{
继续;
}
其他的
{
行。添加(行);
}
}
//System.IO.File.writeAllines(outFolderName+“twotations.csv”,line.ToArray());
}
System.IO.File.writeAllines(outFolderName+“Facebook Insights.csv”,lines.ToArray());
文件。删除(f.FullName);
}
Dts.TaskResult=(int)ScriptResults.Success;
}
#区域脚本结果声明
枚举脚本结果
{
Success=Microsoft.SqlServer.Dts.Runtime.dtsesecresult.Success,
Failure=Microsoft.SqlServer.Dts.Runtime.dtsesecresult.Failure
};
#端区
}
}

我的问题问题出在哪里

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

见此:

脚本错误很可能是权限问题!!如果包在本地工作,但不在服务器上工作,那么很可能从SQL agent执行包的用户没有权限访问脚本中的网络位置。文件访问抛出一个异常,这将为您提供无用的SSIS脚本任务异常。您应该在第一次访问文件后注释掉所有内容,以隔离错误消息,看看这是否是导致问题的原因。
#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
    }
}