我正在升级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))
这一行处出现问题。我收到了以下错误。
这里是异常详情:
用户代码处理 System.ArgumentException 未被处理 HResult=-2147024809 Message=路径中存在非法字符。 Source=mscorlib StackTrace: 在 System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath) 在 System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) 在 System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) 在 System.IO.StreamWriter.CreateFile(String path, Boolean append, Boolean checkHost) 在 System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost) 在 System.IO.StreamWriter..ctor(String path, Boolean append) 在 System.IO.File.AppendText(String path) 在 ST_9752d9eb585d4a4d97a334ef01ccf313.ScriptMain.Main() 位置:c:\Users\aluhman\AppData\Local\Temp\2\Vsta\5c1672d48682401d852b1b44649f951b\ScriptMain.cs 第 31 行 InnerException:这些都是2005年就已经工作的,而这是我现在在2016年看到的一个新错误。
fileName
文件名。 - Subbu