通过SSIS运行时,VB.net 4.5.exe无法执行
我编写了一个vb.net控制台程序,该程序链接到数据库,主要功能是通过将不同配置的单独PDF页面连接在一起来生成报告包 为了做到这一点,我不得不使用一些变通方法,但已经在本地测试了构建和部署的应用程序&手动测试,效果很好。这些措施如下: 我需要通过SSIS调用应用程序,以便将其作为更广泛的代理作业的一部分进行调度 我无法远程访问运行作业的SSIS服务器,尽管我可以通过SSMS/Trigger the job等连接到该服务器&我可以看到应用程序.exe和关联文件所在文件夹的共享 因为我没有在服务器上安装应用程序的权限,所以我采取了在本地安装visual studio的click once输出并从本地apps文件夹中提取.exe和相关文件的方法。然后将这些文件复制到文件共享中。我再次测试了.exe文件可以在那里手动运行,同时使用我的凭据登录,这没有问题,并产生预期的输出文件和日志文件 当SSIS作业运行时,它使用一个服务帐户-我不能确定该帐户是否有权访问共享驱动器,但由于它能够为其他作业移动驱动器上的文件,我假设这是真的。我还创建了一个更基本的控制台应用程序,它只读取XML文件中的值,但不写入任何输出,运行成功 我查看了SSMS,可以看到共享文件位于代理服务器的G:上。我假设.exe也将在代理服务器上执行,因此我尝试将文件路径映射到G:和文件共享。因为我假设证券将根据您处理文件夹的方式而有所不同 创建PDF所需的加载项不接受UNC文件路径,因此我需要为其提供相对或映射的文件夹路径。我无法映射驱动器,因为我不知道代理帐户密码-但如果绝对必要,可以解决此问题。目前,我从XML配置文件加载相对路径 当应用程序从共享文件夹位置以我自己的帐户手动运行时,它会按预期创建日志文件 通过SSIS运行应用程序时,作业失败,错误代码为:-2146232576,并且未创建任何日志文件 由于日志文件是应用程序要做的第一件事,我认为它失败了,因为它无法写入输出 是否有人知道一种确认方法: A.)运行.exe的位置(包从G:文件路径调用.exe) b、 )代理帐户在其运行的目录上具有什么权限 C.)错误代码的含义 D.)如果我在这里完全遗漏了什么通过SSIS运行时,VB.net 4.5.exe无法执行,.net,sql-server,vb.net,windows,ssis,.net,Sql Server,Vb.net,Windows,Ssis,我编写了一个vb.net控制台程序,该程序链接到数据库,主要功能是通过将不同配置的单独PDF页面连接在一起来生成报告包 为了做到这一点,我不得不使用一些变通方法,但已经在本地测试了构建和部署的应用程序&手动测试,效果很好。这些措施如下: 我需要通过SSIS调用应用程序,以便将其作为更广泛的代理作业的一部分进行调度 我无法远程访问运行作业的SSIS服务器,尽管我可以通过SSMS/Trigger the job等连接到该服务器&我可以看到应用程序.exe和关联文件所在文件夹的共享 因为我没有在服务器
Imports PdfSharp
Imports PdfSharp.Drawing
Imports PdfSharp.Pdf
Imports PdfSharp.Pdf.IO
Imports System.Data.SqlClient
Module Module1
Sub Main(ByVal args() As String)
Dim eventlog As System.IO.StreamWriter
eventlog = My.Computer.FileSystem.OpenTextFileWriter("\\csimccs01\FTP\Out\PDFCREATOR\log.txt", True)
eventlog.WriteLine(Now() & " Process Started at")
Dim countargs = 0
Dim FY As String = ""
Dim FP As String = ""
Dim con1 As New SqlConnection
Dim con2 As New SqlConnection
Dim con3 As New SqlConnection
Dim cmd1 As New SqlCommand
Dim cmd2 As New SqlCommand
Dim cmd3 As New SqlCommand
Dim sqldataset2 As SqlDataReader
Dim packid As Integer
Dim LV7Symbol As String
Dim PackDescription As String
Dim SPPATH As String
Dim RptVer As Integer
Dim outputdoc As PdfDocument
Dim PDFCount As Integer
Dim progress As Integer = 0
Dim importdoc As PdfDocument
Dim count As Integer
Dim constr As String
Dim inputfilefolder As String
Dim outputfilefolder As String
Dim fullinputfilepath As String
Dim outputfilename As String
eventlog.WriteLine(Now() & " Looking for config file")
Try
If My.Computer.FileSystem.FileExists("\\csimccs01\FTP\Out\PDFCREATOR\config.xml") Then
Dim xmlconfig = XDocument.Load("\\csimccs01\FTP\Out\PDFCREATOR\config.xml")
constr = xmlconfig.<config>.<DBCONNECTIONSTRING>.Value
inputfilefolder = xmlconfig.<config>.<FilePath>.<Input>.Value
outputfilefolder = xmlconfig.<config>.<FilePath>.<Output>.Value
eventlog.WriteLine(Now() & " Config file loaded and variables set")
eventlog.WriteLine(Now() & " inputfolder: " & inputfilefolder)
eventlog.WriteLine(Now() & " outputfolder: " & outputfilefolder)
Else
eventlog.WriteLine(Now() & " Config File Not Found")
Exit Sub
End If
Catch ex As Exception
Console.WriteLine(1)
eventlog.WriteLine(Now() & " Config File Not Found, routine exited by exception")
eventlog.Close()
Exit Sub
End Try
countargs = 0
eventlog.WriteLine(Now() & " Setting Fiscal Year & Period Variables")
If FY = "" Then
FY = "FY2016"
End If
If FP = "" Then
FP = "FP01"
End If
eventlog.WriteLine(Now() & " Fiscal Year & Period Variables set")
Try
eventlog.WriteLine(Now() & " Attempting to open database con1")
con1.ConnectionString = constr
con1.Open()
eventlog.WriteLine(Now() & " Con1 open")
cmd1.Connection = con1
cmd1.CommandText = "SELECT [PackID],[LV7Symbol],[LV7Description],[SharePoint_Output_Path],[Report_Version] FROM [D_EXP_CPM].[dbo].[FACT_REPORT_CONTROL_TABLE]"
Dim sqldataset1 As SqlDataReader = cmd1.ExecuteReader()
eventlog.WriteLine(Now() & " Report List loaded into Dataset1")
eventlog.WriteLine(Now() & " Starting to loop through Dataset1")
While sqldataset1.Read()
packid = sqldataset1.Item("PackID")
LV7Symbol = sqldataset1.Item("LV7Symbol").ToString
PackDescription = sqldataset1.Item("LV7Description").ToString
SPPATH = sqldataset1.Item("SharePoint_Output_Path").ToString
RptVer = sqldataset1.Item("Report_Version") + 1
eventlog.WriteLine(Now() & " Pack level variables set for pack id " & packid)
eventlog.WriteLine(Now() & " Opening connection3 to update version number")
con3.ConnectionString = constr
con3.Open()
cmd3.Connection = con3
cmd3.CommandText = "UPDATE [D_EXP_CPM].[dbo].[FACT_REPORT_CONTROL_TABLE] SET [Report_Version]=" & RptVer & " WHERE [PackID] =" & packid
cmd3.ExecuteNonQuery()
con3.Close()
eventlog.WriteLine(Now() & " Version Updated")
eventlog.WriteLine(Now() & " Connection 3 closed")
Try
eventlog.WriteLine(Now() & " Opening connection2")
con2.ConnectionString = constr
con2.Open()
cmd2.Connection = con2
cmd2.CommandText = "SELECT [EntryID],[PackID], [TemplateID], [SortOrder] FROM [D_EXP_CPM].[dbo].[FACT_REPORTPACK_PAGE_CONFIG] WHERE [PACKID] = " & packid & " Order By [PackID], [SortOrder]"
sqldataset2 = cmd2.ExecuteReader()
eventlog.WriteLine(Now() & " Results or pack page configuration loaded into sqldatset2")
eventlog.WriteLine(Now() & " Opening temporary PDF")
outputdoc = New PdfDocument
eventlog.WriteLine(Now() & " Starting to loop through Pack pages for pack " & packid)
While sqldataset2.Read()
If Not sqldataset2.HasRows Then
eventlog.WriteLine(Now() & " No template configuration data found for packid " & packid)
GoTo nextrpt
End If
fullinputfilepath = inputfilefolder & "\CC " & LV7Symbol & "_TID" & (sqldataset2.Item("TemplateID") - 1) & "_" & FP & "_" & FY & ".pdf"
eventlog.WriteLine(Now() & " input file path set to: " & fullinputfilepath)
Try
eventlog.WriteLine(Now() & " attempting to read input file")
importdoc = PdfReader.Open(fullinputfilepath, PdfSharp.Pdf.IO.PdfDocumentOpenMode.Import)
eventlog.WriteLine(Now() & " inputfile read successfully")
Catch ex As Exception
eventlog.WriteLine(Now() & " Unable to read intput file, move to next report")
GoTo nextrpt
End Try
count = importdoc.PageCount
progress = 0
Do Until progress = count
Dim pdfpage As PdfPage = importdoc.Pages(progress)
outputdoc.AddPage(pdfpage)
progress = progress + 1
Loop
eventlog.WriteLine(Now() & " incrementing pdf page count")
PDFCount = PDFCount + 1
End While
eventlog.WriteLine(Now() & " all pages of input file consolidated")
PackDescription.Replace("&", "and")
eventlog.WriteLine(Now() & " '&' charcter removed from file names")
outputfilename = outputfilefolder & "\" & LV7Symbol & "_" & FY & "_" & FP & "_" & PackDescription & "_VER" & RptVer & ".pdf"
eventlog.WriteLine(Now() & " attempting to save output PDF as: " & outputfilename)
If outputdoc.PageCount > 0 Then
outputdoc.Save(outputfilename)
End If
eventlog.WriteLine(Now() & " output file saved")
nextrpt:
Catch ex As Exception
eventlog.WriteLine(Now() & " Exception encountered in page level try catch")
Finally
con2.Close()
eventlog.WriteLine(Now() & " Connection 2 closed")
End Try
End While
Catch ex As Exception
Console.WriteLine(1)
eventlog.WriteLine(Now() & " Exception encountered in report level try catch")
eventlog.Close()
Exit Sub
Finally
con1.Close()
eventlog.WriteLine(Now() & " Connection 1 closed")
End Try
Console.WriteLine(0)
eventlog.WriteLine(Now() & " Process completed successfully")
eventlog.Close()
Exit Sub
End Sub
End Module
导入PdfSharp
导入PdfSharp.Drawing
导入PdfSharp.Pdf
导入PdfSharp.Pdf.IO
导入System.Data.SqlClient
模块1
Sub Main(ByVal args()作为字符串)
将事件日志设置为System.IO.StreamWriter
eventlog=My.Computer.FileSystem.OpenTextFileWriter(\\csimcs01\FTP\Out\PDFCREATOR\log.txt),True)
WriteLine(现在()&“进程开始于”)
Dim countargs=0
Dim FY As String=“”
Dim FP As String=“”
Dim con1作为新的SqlConnection
Dim con2作为新的SqlConnection
Dim con3作为新的SqlConnection
Dim cmd1作为新的SqlCommand
Dim cmd2作为新的SqlCommand
Dim cmd3作为新的SqlCommand
将sqldataset2设置为SqlDataReader
作为整数的Dim packid
将LV7符号标注为字符串
Dim PACK描述为字符串
将路径设置为字符串
将RptVer设置为整数
作为PDF文档的Dim outputdoc
Dim PDFCount为整数
将进度调整为整数=0
作为PDF文档的Dim importdoc
将计数设置为整数
Dim constr As字符串
Dim inputfilefolder作为字符串
Dim outputfilefolder作为字符串
Dim fullinputfilepath作为字符串
Dim outputfilename作为字符串
WriteLine(现在()&“查找配置文件”)
尝试
如果My.Computer.FileSystem.files存在(“\\csimcs01\FTP\Out\PDFCREATOR\config.xml”),则
Dim xmlconfig=XDocument.Load(“\\csimcs01\FTP\Out\PDFCREATOR\config.xml”)
constr=xmlconfig…值
inputfilefolder=xmlconfig….值
outputfilefolder=xmlconfig….值
WriteLine(现在()&“加载配置文件并设置变量”)
WriteLine(现在()&“inputfolder:”&inputfilefolder)
WriteLine(现在()&“outputfolder:”&outputfilefolder)
其他的
WriteLine(现在()&“未找到配置文件”)
出口接头
如果结束
特例
控制台写入线(1)
WriteLine(现在()&“未找到配置文件,例程因异常退出”)
eventlog.Close()
出口接头
结束尝试
countargs=0
WriteLine(现在()&设置会计年度和期间变量)
如果FY=”“,则
FY=“2016财年”
如果结束
如果FP=”“,则
FP=“FP01”
如果结束
eventlog.WriteLine(现在()&“会计年度和期间变量集”)
尝试
WriteLine(现在()&“正在尝试打开数据库con1”)
con1.ConnectionString=CONT
con1.Open()
eventlog.WriteLine(现在()和“Con1打开”)
cmd1.Connection=con1
cmd1.CommandText=“从[D_EXP_CPM].[dbo].[FACT_Report_CONTROL_TABLE]中选择[PackID]、[LV7Symbol]、[LV7Description]、[SharePoint_Output_Path]、[Report_Version]。”
作为SqlDataReader=cmd1.ExecuteReader()的Dim sqldataset1
WriteLine(现在()&“报告列表加载到数据集1”)
eventlog.WriteLine(现在为()