我在SSIS包中有一个脚本任务,它应该从注册表中检索字符串值。如果注册表值存在并且其中包含值,则表示返回值为fine。如果注册表项不存在或值为空,则由于某种原因我无法使其默认值。我已经尝试了三种不同的方式,但无法使其发挥作用 我已经尝试使用Registry.GetValue并指定一个默认的Registry.LocalMachine.CreateSubKey和Registry.LocalMachine.GetValue。我甚至尝试过显式检查null或0长度,似乎没有任何作用......我做错了吗?
Public Sub Main()
'Dim strValue As String = DirectCast(Registry.LocalMachine.GetValue("SOFTWARE\MyComp\SSIS\IPSEmail\strLastDate", DateTime.Now.ToString("MMM dd, yyyy HH:mm:ss")), String)
'Dim strValue As String = DirectCast(Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\MyComp\SSIS\IPSEmail", "strLastDate", DateTime.Now.ToString("MMM dd, yyyy HH:mm:ss")), String)
Dim strValue As String = DirectCast(Registry.LocalMachine.CreateSubKey("SOFTWARE\MyComp\SSIS\IPSEmail\strLastDate").GetValue("strLastDate", DateTime.Now.ToString("MMM dd, yyyy HH:mm:ss")), String)
If (strValue = Nothing Or strValue.Length = 0) Then
strValue = DateTime.Now.ToString("MMM dd, yyyy HH:mm:ss")
End If
Dts.ExecutionValue = strValue
Dts.TaskResult = Dts.Results.Success
End Sub
答案 0 :(得分:1)
您是否尝试过strValue Is Nothing
?
如果这不起作用,请在代码中放置一个断点,并找出声明它时设置的strValue
,并且注册表项不存在。