【发布时间】:2018-04-05 00:57:42
【问题描述】:
在使用 DTEXEC 从 .bat 文件运行包含脚本任务的 SSIS 包时,我收到以下错误。使用“EXEC xp_cmdshell”从 MS SQL 中的存储过程调用 .bat 文件
错误: 代码:0x00000001 说明:调用的目标已抛出异常。
当我在 Visual Studio 中运行 SSIS 包时,它运行良好。 当我手动运行 .bat 文件时,它运行良好。 我收到错误的唯一一次是在运行存储过程时。
这是脚本任务:
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.IO
Imports System.IO.FileInfo
<Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute()>
<System.CLSCompliantAttribute(False)>
Partial Public Class ScriptMain
Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
Enum ScriptResults
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
End Enum
Protected Sub SaveFile(ByVal url As String, ByVal localpath As String)
Dim loRequest As System.Net.HttpWebRequest
Dim loResponse As System.Net.HttpWebResponse
Dim loResponseStream As System.IO.Stream
Dim loFileStream As New System.IO.FileStream(localpath, System.IO.FileMode.Create, System.IO.FileAccess.Write)
Dim laBytes(256) As Byte
Dim liCount As Integer = 1
Try
loRequest = CType(System.Net.WebRequest.Create(url), System.Net.HttpWebRequest)
loRequest.Credentials = System.Net.CredentialCache.DefaultCredentials
loRequest.Timeout = 600000
loRequest.Method = "GET"
loResponse = CType(loRequest.GetResponse, System.Net.HttpWebResponse)
loResponseStream = loResponse.GetResponseStream
Do While liCount > 0
liCount = loResponseStream.Read(laBytes, 0, 256)
loFileStream.Write(laBytes, 0, liCount)
Loop
loFileStream.Flush()
loFileStream.Close()
Catch ex As Exception
End Try
End Sub
Public Sub Main()
Dim url, destination, newname As String
destination = Dts.Variables("Folder_Destination").Value.ToString + "\" + Dts.Variables("FileName").Value.ToString + ".xpdf"
url = "http://localhost/reportserver?/PDFExport/DEVOrderPDF&rs:Command=Render" + Dts.Variables("FileName").Value.ToString + "&rs:Format=PDF"
SaveFile(url, destination)
newname = Path.GetFileNameWithoutExtension(destination) + ".pdf"
My.Computer.FileSystem.RenameFile(destination, newname)
Dts.TaskResult = ScriptResults.Success
End Sub
End Class
我将补充一点,当运行存储过程时,我看到文件正在使用 .xpdf 扩展名创建,但是大小为 0kb,并且在将扩展名更改为 .pdf 时无法打开。它几乎就像它部分运行,但在调用 SSRS url 时没有完成。
【问题讨论】:
-
您对 SSRS 使用什么类型的身份验证?您是否检查了事件查看器 - 安全 - 未能检查用于连接 SSRS 的帐户的审核?
-
我对 SSRS 很陌生,但我相信我使用的是 Windows 身份验证。我检查了事件查看器并看到了几个失败的审核。我也看到了帐户名称,但我该去哪里更改/更正它?
-
我找到了在 IIS 管理器中更改运行报告的帐户名称的位置。事件查看器现在显示成功的审核,但问题仍然存在。
-
您应该使用 using 语句或在 finally 块中释放文件句柄。事实上,如果抛出异常,您的文件句柄将不会被释放。
标签: sql-server visual-studio reporting-services ssis