![](/img/trans.png)
[英]Exception has been thrown by the target of an invocation (SSIS & WinSCP & C#)
[英]Exception has been thrown in C# Script in SSIS
我在 SSIS 2010 中徘徊,将我的项目从我的电脑转移到服务器,但我遇到了 C# 脚本任务的问题,它在我的电脑上运行得很好,但在服务器中它给了我一个错误。
我执行脚本时出现此错误
这就是 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
}
}
我的问题是哪里出了问题
我有一种感觉,这可能是您的文件夹 URI。 当一个包在您的用户 ID 下运行时,它会使用您的权限,但是当从 sql 代理运行时,您必须确保它在正确的权限下运行,以便允许它访问该网络位置。
看到这个:
http://bi-polar23.blogspot.com/2007/12/ssis-and-sql-server-agent.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.