【发布时间】:2017-12-26 11:01:21
【问题描述】:
我正在努力将 2005 SSIS 包升级到 2016。我已经升级了这个包,但是当我尝试运行它时,它会中断控制流中的脚本任务。
#region Namespaces
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.IO;
#endregion
namespace ST_9752d9eb585d4a4d97a334ef01ccf313
{
[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
public void Main()
{
string fileName;
fileName = Dts.Variables["User::Source_File_And_Path"].Value.ToString();
using (StreamWriter w = File.AppendText(fileName))
{
w.Write("\r\n");
w.Close();
}
Dts.TaskResult = (int)ScriptResults.Success;
}
#region ScriptResults declaration
/// <summary>
/// This enum provides a convenient shorthand within the scope of this class for setting the
/// result of the script.
///
/// This code was generated automatically.
/// </summary>
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
}
}
此脚本任务用于将 CRLF 添加到文件中数据的末尾。我在代码中添加了断点,我看到它在 using (StreamWriter w = file.AppendText(fileName)) 行处中断。 I am receiving the following error.
以下是异常详情:
System.ArgumentException 未被用户代码处理 H结果=-2147024809 消息=路径中有非法字符。 源=mscorlib 堆栈跟踪:
在 System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath) 在 System.IO.FileStream.Init(字符串路径、FileMode 模式、FileAccess 访问、Int32 权限、Boolean useRights、FileShare 共享、Int32 bufferSize、FileOptions 选项、SECURITY_ATTRIBUTES secAttrs、String msgPath、Boolean bFromProxy、Boolean useLongPath、Boolean checkHost) 在 System.IO.FileStream..ctor(字符串路径,FileMode 模式,FileAccess 访问,FileShare 共享,Int32 bufferSize,FileOptions 选项,字符串 msgPath,布尔 bFromProxy,布尔 useLongPath,布尔 checkHost) 在 System.IO.StreamWriter.CreateFile(字符串路径,布尔附加,布尔检查主机) 在 System.IO.StreamWriter..ctor(字符串路径,布尔附加,编码编码,Int32 缓冲区大小,布尔检查主机) 在 System.IO.StreamWriter..ctor(字符串路径,布尔附加) 在 System.IO.File.AppendText(字符串路径) 在 ST_9752d9eb585d4a4d97a334ef01ccf313.ScriptMain.Main() 在 c:\Users\aluhman\AppData\Local\Temp\2\Vsta\5c1672d48682401d852b1b44649f951b\ScriptMain.cs:line 31 内部异常:
这一切都在 2005 年有效,这是我现在在 2016 年看到的一个新错误。
【问题讨论】:
-
尝试将异常详细信息复制到剪贴板。然后粘贴到记事本中。那么错误可能是由于文件名包含文件名中不允许的字符。
-
检查你的
fileName -
这是文件名“F:\\Data_Imports\\Company\\Inbound\\Customers_*.txt”
标签: c# sql-server ssis