Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to run an application from a SQL Job

Status
Not open for further replies.

mdProgrammer

Programmer
Oct 2, 2004
71
0
0
US
I created a simple test application that automatically sends an email (it's eventual use will be sending secure email based on what's in a table - yes, I know about SQL Server 2008's email capabilities, but it's not set up, and I'm not the one that sets the servers up). This application works on my local computer.

For reference, this is the code (there's no input needed) -

Code:
Imports Outlook = Microsoft.Office.Interop.Outlook


Public Class Form1

    Private Account As Outlook.Account
    Private olApp As Outlook.Application
    Private olSession As Outlook.NameSpace

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim olAccounts As Outlook.Accounts

        olApp = New Outlook.Application()
        olSession = olApp.Session
        olAccounts = olSession.Accounts

        Account = olSession.Accounts(1)

        ' Create the Email
        Dim item As Outlook.MailItem
        Me.Hide()
        item = olApp.CreateItem(Outlook.OlItemType.olMailItem)
        item.Subject = "Test Subject" 'TextBox2.Text
        item.Body = "Test Message" 'RichTextBox1.Text
        item.Recipients.Add("jgasiorowski@dors.state.md.us") 'TextBox1.Text)
        item.Recipients.ResolveAll()
        item.Send()
        Close()
    End Sub

Now, I created a SQL Job on my SQL Server database whose only step is to run this application. The setup is:

Type: Operating System (CmdExec)
Run As: SQL Server Agent Service Account
Command: E:\Projects\test\EmailTest\EmailTest\bin\Release\EmailTest.exe
The owner is myself.

When I run the job, it hangs at "Execute Job 'TestEmail'". I've read some things about security permissions, and I even tried giving "everyone" full control (I know that's a security hazard, but that's just for testing), and it still didn't work. Anyone have any suggestions?
 
I would suggest a slight change to your process.

Instead of using SQL Server agent to run the external app, I would encourage you to use Windows task scheduler to run it instead. You will have the same flexibility regarding the schedule, but you will have less "weirdness" regarding permissions.



-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top