Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SSIS变量表达式上的子字符串_C#_Variables_Ssis_Substring - Fatal编程技术网

C# SSIS变量表达式上的子字符串

C# SSIS变量表达式上的子字符串,c#,variables,ssis,substring,C#,Variables,Ssis,Substring,我有这样的SSIS变量表达式 @[System::PackageName]+","+ @[System::SourceName]+","+ (DT_STR,15,1252) @[System::ErrorCode]+","+ @[System::ErrorDescription]+","+ (RIGHT((DT_WSTR,4) DATEPART("yyyy",GetDate()),4)+"/"+ RIGHT("0"+(DT_WSTR , 2) DATEP

我有这样的SSIS变量表达式

@[System::PackageName]+","+    
@[System::SourceName]+","+    
(DT_STR,15,1252) @[System::ErrorCode]+","+    
@[System::ErrorDescription]+","+    
(RIGHT((DT_WSTR,4)
DATEPART("yyyy",GetDate()),4)+"/"+    
RIGHT("0"+(DT_WSTR , 2)
 DATEPART("mm", GetDate()),2)+"/"+    
RIGHT("0"+(DT_WSTR,2)
DATEPART("dd",GetDate()),2)+"_"+    
RIGHT("0"+(DT_WSTR,2)
DATEPART("HH",GetDate()),2)+":"+    
RIGHT("0"+(DT_WSTR,2)
DATEPART("MM",GetDate()),2)+":"+    
RIGHT("0"+(DT_WSTR,2)
DATEPART("SS",GetDate()),2))+","+
 @[System::MachineName]
现在,我想从
@[System::ErrorDescription]
中获取一些字符串,它位于
之前的
处,下面是
@[System::ErrorDescription]
值的示例

System.Reflection.TargetInvocationException:调用的目标已引发异常。-->System.IO.DirectoryNotFoundException:找不到路径“D:\blabl\yes.txt”的一部分。
在System.IO.\uuu Error.WinIOError(Int32 errorCode,字符串maybeFullPath)
在System.IO.FileStream.Init(字符串路径、文件模式、文件访问权限、Int32权限、布尔用户权限、文件共享、Int32缓冲大小、文件选项选项、安全属性secAttrs、字符串msgPath、布尔bFromProxy)
位于System.IO.FileStream..ctor(字符串路径、文件模式、文件访问权限、文件共享、Int32 bufferSize、文件选项选项、字符串msgPath、布尔bFromProxy)
位于System.IO.FileStream..ctor(字符串路径、文件模式、文件访问权限、文件共享共享、Int32 bufferSize)
位于System.Xml.XmlDownloadManager.GetStream(Uri、ICredentials凭据)
位于System.Xml.XmlUrlResolver.GetEntity(Uri绝对Uri、字符串角色、对象类型返回)
位于System.Xml.XmlTextReaderImpl.OpenUrlDelegate(对象xmlResolver)
在System.Threading.CompressedStack.runTryCode(对象用户数据)处
在System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode代码、CleanupCode backoutCode、Object userData)中运行
在System.Threading.CompressedStack.Run(CompressedStack CompressedStack,ContextCallback回调,对象状态)

我所做的是在变量表达式上编写子字符串代码:

SUBSTRING(@[System::ErrorDescription],1,FINDSTRING(@[System::ErrorDescription],“at”,1)-1)+“,”+


但是它总是给我一个错误,子字符串值不能为负,我的代码有什么问题吗?

如果
查找字符串(@[System::ErrorDescription],“at”,1)
的结果为零(即未找到字符串),那么子字符串表达式的最后一个参数变为
-1
。这是一个常见的问题

也许您可以尝试评估它是否为零,如果不是,则只使用Findstring。为了清楚起见,我将下面的表达式拆分了,但它应该全部放在一行上。我没有SSI要测试,但看看它是否有效

我不认为你已经发布了你的完整表达,但这应该给你的想法

FINDSTRING(@[System::ErrorDescription], "at", 1)==0
   ?
"Nothing Found"
   :
SUBSTRING(
    @[System::ErrorDescription], 
    1, 
    FINDSTRING(@[System::ErrorDescription], "at", 1)-1
)
下面是一个描述条件的链接:


我不相信这是完整的故事,但尝试一下,它将刷新您的下一期。

我已经更改了值,但它会给我不同的错误,因此,如果我想在at之后删除字符串,我应该使用什么类型的表达式…?看起来您将竭尽全力捕获错误,并在过程中引发更多错误。您不想使用内置错误日志记录的任何原因?