问题描述
在我的PC上,通过开始"按钮运行此工具,一切运行都很好.当我生成可执行文件并将可执行文件复制到生产机器并通过生产计算机上的SQL Server代理计划作业时,一切正常,可以创建文件,但是加密位不起作用.gpg.exe在生产服务器上位于:\ sql2014 \ c $ \ Program Files(x86)\ GnuPG \ bin
Everything worked great from my Visual Studio on my PC running this from the Start button. When I build the executable and copied the executable to the production box and scheduled the job via SQL Server Agent on the production machine – everything worked fine to create the file, but the encryption bit does not work.The gpg.exe is here on the production server: \sql2014\c$\Program Files (x86)\GnuPG\bin
gpg在我的PC上:C:\ Program Files(x86)\ GnuPG \ bin
The gpg is here on my PC: C:\Program Files (x86)\GnuPG\bin
在正确的位置创建filename.csv,好了-我测试了这两个名称Dim Extract_File As String ="\ sql2014 \ e $ \ Extracts \ ProgramName \ filename.csv"‘Dim Extract_File As String ="E:\ Extracts \ ProgramName \ filename.csv"‘从我的PC上执行此操作,我必须将E:更改为C:
The filename.csv gets created in the proper location ok - I tested with both these namesDim Extract_File As String = "\sql2014\e$\Extracts\ProgramName\filename.csv"‘Dim Extract_File As String = "E:\Extracts\ProgramName\filename.csv" ‘do to this from my PC I had to change the E: to a C:
此行调用该函数: FileEncrypted = Encrypt_File(Extract_File,Batch_Timestamp)
This line calls the function: FileEncrypted = Encrypt_File(Extract_File, Batch_Timestamp)
Private Function Encrypt_File(File_To_Encrypt As String, Batch_Timestamp As Date)
On Error GoTo Encrypt_File_Error
Dim Success As Boolean = False
Dim sourceName As String = File_To_Encrypt
Dim gpgProcess = New Process()
‘Test with working directory - no effect
‘gpgProcess.StartInfo.UseShellExecute = False
'gpgProcess.StartInfo.WorkingDirectory = "\\sql2014\c$\Program Files (x86)\GnuPG\bin\"
‘gpgProcess.StartInfo.FileName = "gpg.exe"
gpgProcess.StartInfo.FileName = \\sql2014\c$\Program Files (x86)\GnuPG\bin\gpg.exe ‘This works from my PC
‘gpgProcess.StartInfo.FileName = \\sql2014\c$\Program Files (x86)\GnuPG\bn\gpg.exe ‘If I change this path took the "i" out of bin I get an error: The system cannot find the file specified
gpgProcess.StartInfo.UseShellExecute = False
gpgProcess.StartInfo.CreateNoWindow = True
gpgProcess.StartInfo.Arguments = "--batch --yes --recipient reciptname --encrypt " & sourceName
gpgProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
gpgProcess.Start()
gpgProcess.WaitForExit()
If FileExists(sourceName & ".gpg") Then
Success = True
End If
Encrypt_File_Exit:
On Error Resume Next
‘gpgProcess.WaitForExit() moved this up to
gpgProcess.Close()
Return Success
Exit Function
Encrypt_File_Error:
Error_Handler("SomeModule.vb", "Encrypt_File", Err, System_Output, Batch_Timestamp)
Resume Encrypt_File_Exit
End Function
有关如何解决此问题的任何建议.当在我的PC上运行时,它将在与filename.csv相同的目录中创建filename.csv.gpg.在生产服务器上,它不会创建gpg,也不会给出可见的错误消息.
Any suggestions for how I can resolve this. When it worked on my PC it creates a filename.csv.gpg in the same directory as filename.csv. On the production server it does not create the gpg and it does not give a visible error message either.
推荐答案
这是我解决此问题的方法.我从NuGet软件包管理器安装了OpenPgpLib,并重新编写了此函数,如下所示.我使用Kleopatra工具创建了.asc文件,并将其保存在下面代码位的pubkey中使用的位置. OpenPgp来自软件包.
This is how I solved this issue. I Installed the OpenPgpLib from the NuGet Package Manager and re-wrote this Function as shown here.I created the .asc file from the Kleopatra tool and saved it in the location used in the pubkey in the code bit below. The OpenPgp is from the package.
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
这篇关于vb.net运行gpg.exe作业步骤可以从PC上正常运行,但不能从SQL Server代理计划中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!