Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Trying to run an application from a SQL Job

Trying to run an application from a SQL Job

Trying to run an application from a SQL Job

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) -


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
        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)
    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?

RE: Trying to run an application from a SQL Job

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.

Microsoft SQL Server MVP
My Blogs
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close