vb.net运行作业的gpg.exe步骤从PC运行正常,但不从SQL Server代理计划运行

vb.net运行作业的gpg.exe步骤从PC运行正常,但不从SQL Server代理计划运行,vb.net,filepath,gnupg,hidden-files,executable-path,Vb.net,Filepath,Gnupg,Hidden Files,Executable Path,从我的PC上的VisualStudio开始,从开始按钮开始运行,一切都很好。当我构建可执行文件并将其复制到生产箱中,并通过生产机器上的SQL Server代理计划作业时,创建文件的所有工作都正常,但加密位不起作用。 gpg.exe位于生产服务器上:\sql2014\c$\Program Files(x86)\GnuPG\bin gpg在我的电脑上:C:\ProgramFiles(x86)\GnuPG\bin 在正确的位置创建filename.csv好的-我用这两个名称进行了测试 Dim Extr

从我的PC上的VisualStudio开始,从开始按钮开始运行,一切都很好。当我构建可执行文件并将其复制到生产箱中,并通过生产机器上的SQL Server代理计划作业时,创建文件的所有工作都正常,但加密位不起作用。 gpg.exe位于生产服务器上:\sql2014\c$\Program Files(x86)\GnuPG\bin

gpg在我的电脑上:C:\ProgramFiles(x86)\GnuPG\bin

在正确的位置创建filename.csv好的-我用这两个名称进行了测试 Dim Extract_文件格式为字符串=“\sql2014\e$\Extracts\ProgramName\filename.csv” 'Dim Extract\u File As String=“E:\Extracts\ProgramName\filename.csv”'要从我的电脑中执行此操作,我必须将E:更改为C:

此行调用函数: FileEncrypted=加密文件(提取文件、批处理时间戳)


关于如何解决此问题的任何建议。当它在我的电脑上工作时,它会在filename.csv所在的目录中创建filename.csv.gpg。在生产服务器上,它不会创建gpg,也不会给出可见的错误消息。

这就是我解决此问题的方法。我从NuGet软件包管理器安装了OpenPgpLib,并重新编写了此函数,如图所示。 我从Kleopatra工具创建了.asc文件,并将其保存在下面代码位的pubkey中使用的位置。OpenPgp来自该软件包

    Private Function Encrypt_File(File_To_Encrypt As String, Log_File As String, Batch_Timestamp As Date)
        Dim Success As Boolean = False
        Dim encryptthis As String = File_To_Encrypt
        Dim thisencrypted As String = File_To_Encrypt & ".gpg"
        Dim pubkey As String = "\\sql2014\c$\Data_Programs\MyDirectory\<thepublickeyfile>.asc"
        Try
            OpenPgp.EncryptFile(encryptthis, thisencrypted, pubkey, False, False)
            If FileExists(thisencrypted) Then
                Success = True
            End If
        Catch ex As Exception
            App_Logger(Log_File, ex.StackTrace.ToString(), System_Output, Batch_Timestamp)
            Success = False
        End Try
        Return Success
    End Function
私有函数加密文件(文件加密为字符串,日志文件加密为字符串,批处理时间戳加密为日期)
将成功设置为布尔值=False
Dim encryptthis As String=File\u To\u Encrypt
Dim This Encrypted As String=文件\u To \u Encrypt&“.gpg”
Dim pubkey As String=“\\sql2014\c$\Data\u Programs\MyDirectory\.asc”
尝试
OpenPgp.EncryptFile(encryptthis,thisencrypted,pubkey,False,False)
如果文件存在(thisencrypted),则
成功=正确
如果结束
特例
应用程序记录器(日志文件,ex.StackTrace.ToString(),系统输出,批处理时间戳)
成功=错误
结束尝试
回归成功
端函数
    Private Function Encrypt_File(File_To_Encrypt As String, Log_File As String, Batch_Timestamp As Date)
        Dim Success As Boolean = False
        Dim encryptthis As String = File_To_Encrypt
        Dim thisencrypted As String = File_To_Encrypt & ".gpg"
        Dim pubkey As String = "\\sql2014\c$\Data_Programs\MyDirectory\<thepublickeyfile>.asc"
        Try
            OpenPgp.EncryptFile(encryptthis, thisencrypted, pubkey, False, False)
            If FileExists(thisencrypted) Then
                Success = True
            End If
        Catch ex As Exception
            App_Logger(Log_File, ex.StackTrace.ToString(), System_Output, Batch_Timestamp)
            Success = False
        End Try
        Return Success
    End Function