Question : SQL Agent fails to execute a program

Hello,

im trying to execute a simpel program with SQL Agent but it will not go all the way.
The program runs fine if i dubbel click it.
It runs on a Windows 2008 server SP2 64bit, SQL 2005 std 64bit 9.00.4053.00.
SQL Service and SQL Agent runs on domain account with local admin rights.
I try to do som stuff in Excel 2007 and the job starts and Excel *32 starts but will not close and i guess this is the problem?

Any idea why it works when i dubbel click it but not with SQL Agent CmdExec (myprogram)?
(I dubbel click as the same user as runs the SQL Agent.)

My test code is in vb.net 2005

Thanks
Kenneth

    Private Shared Sub TestSaveAS()

        Dim oExcel As Microsoft.Office.Interop.Excel.Application
        Dim oBook, oBook1 As Microsoft.Office.Interop.Excel.Workbook
        Dim oSheet As Microsoft.Office.Interop.Excel.Worksheet

        'Start a new workbook in Excel.
        oExcel = New Microsoft.Office.Interop.Excel.Application
        oBook = oExcel.Workbooks.Add
        oBook1 = oExcel.Workbooks.Add

        'Add data to cells of the first worksheet in the new workbook.
        oSheet = CType(oBook.Worksheets(1), Microsoft.Office.Interop.Excel.Worksheet)
        oSheet.Range("A1").Value = "Last Name"
        oSheet.Range("B1").Value = "First Name"
        oSheet.Range("C1").Value = "Price"

        oSheet.Range("A1:B1").Font.Bold = True
        oSheet.Range("A2").Value = "Doe"
        oSheet.Range("B2").Value = "John"
        oSheet.Range("C2").Value = 12345.456

        oSheet.Range("C2").Cells.NumberFormat = "$0.00"
        oSheet = CType(oBook.Worksheets(2), Microsoft.Office.Interop.Excel.Worksheet)
        oSheet.Range("A1").Value = "Last Name"
        oSheet.Range("B1").Value = "First Name"
        oSheet.Range("C1").Value = "Price"

        oSheet.Range("A1:B1").Font.Bold = True
        oSheet.Range("A2").Value = "Doe"
        oSheet.Range("B2").Value = "John"
        oSheet.Range("C2").Value = 12345.456

        oSheet.Range("C2").Cells.NumberFormat = "$0.00"
        'Save the Workbook and quit Excel.
        oExcel.DisplayAlerts = False
        oBook.SaveAs("c:\Book1.xls")
        oSheet = Nothing
        oBook = Nothing
        oExcel.Quit()
        System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel)
        GC.Collect()

    End Sub

Answer : SQL Agent fails to execute a program

<<Is cmdshell the way to go>>
Please try the following:

1) Verifying the credentials
> Grant explicitely to the agent service account to execute xp_cmdshell in master database
> Try to re-run as-it is

2) If the above does not nork...
> Grant the ability to the agent service account to execute xp_cmdshell in master database
> set up a proxy cmdshell with the agent service account, to do that, run...

exec sp_xp_cmdshell_proxy_account 'YOURDOMAIN\SQLAgentServiceAccount','password'

> then wrap the cmdshell file call into a stored procedure ...
> you can call the above procedure from a job step as a TSQL call as opposed to a direct cmdshell call.

hope this helps...
Random Solutions  
 
programming4us programming4us