I am having trouble getting an exe to work from an exec master cmdshell statement in sql server.
The EXE works fine when I double click it. But when I try to run it with this command in SQL server it does not execute.
EXEC master..xp_cmdshell 'Path\Program.exe'
The program itself is very simple–it is just supposed to send an email alert using an in-house DLL. If it hits an error, it should write that error to a file in the current directory. (Eventually, I want it to set it up to run via a trigger when records are inserted into a particular table).
When I run the program with the statement above, the program does not print out an error message (as shown below) or send an email. How can I tell if it is executing? Hitting an error? What could be going on? The program itself is working properly when I run it via double clicking the path\program.exe.
Imports System.IO
Module Module1
Sub Main()
Try
EmailSenderDLL.EmailSender.send(15, "Alert Text.")
Catch e As Exception
File.WriteAllText(Directory.GetCurrentDirectory() & "\" & Now.Year & Now.Month & Now.Day & Now.Millisecond, e.Message & vbNewLine & e.StackTrace)
End Try
End Sub
End Module
What steps can I take to fix this?
Yes, you can use database-mail with a google account: https://blogs.msdn.com/b/suhde/archive/2009/07/12/how-to-configure-sql-server-database-mail-to-send-email-using-your-windows-live-mail-account-or-your-gmail-account.aspx?Redirected=true
Make sure you open the right port (587) in you firewall to allow SQL Server to talk to google.