• RBarryYoung (3/30/2009)


    Krushna (3/30/2009)


    RBarryYoung (3/28/2009)


    OK, and what happens when you execute this yourself in a Query windows?:

    xp_cmdshell '\\192.10.10.245\E:\PrintToPDFConsole.exe'

    It was showing :

    The network path was not found.

    But after I've changed it to a shared folder 'Test' .

    Now the stored proc is :

    xp_cmdshell '\\192.10.10.245\Test\PrintToPDFConsole.exe'

    Now it is showing the output:

    Access is denied.

    Note that I'm executing on SQL Server 2000.

    This happens because xp_cmdshell cause the SQL Server to execute a DOS command for you on the server in a (probably) unprivileged account. You would need to figure out what account it is using and then give it all of the rights neccesary to get to the share. Note that for security reasons your SysAdmin may intentionally deny this account access to the network.

    Also, I've tried locally.

    I've kept the exe file in C:\.

    and changed the stored proc :

    ALTER proc callExe

    As

    EXEC master.dbo.xp_cmdshell 'C:\PrintToPDFConsole.exe'

    Now the output is :

    NULL

    Unhandled Exception: System.ComponentModel.Win32Exception: No application is associated with the specified file for this operation

    at PrintToPDF.Program.Main(String[] args)

    NULL

    and the exe file did not run again.

    This will not work because it is going to the Server's C: drive and not your client's. You would have to copy your exe to the Server's C: drive.

    ALTER proc callExe

    As

    EXEC master.dbo.xp_cmdshell 'notepad.exe'

    and executed the stored proc callExe, but the execution is going on and not showing any output. The execution time is more that 10 mins and going on...

    Then I forcefully closed the isqlw.exe from Task Manager.

    This probably opened a Notepad window on the server's console screen. A windows command executed from DOS like this will hang until some user exits the Windows app.

    Is that mean exe file can't be executed in sql server 2000 using xp_cmdshell ?

    No, it just means that you are doing it wrong. Remember that SQL Server is a Server. When you execute commands on SQL Server, they execute on the Server, not on your Client.

    Thank you for your reply.

    I have checked on server.

    I've kept the exe file in C:\.

    The stored proc is:

    ALTER proc callExe

    As

    EXEC master.dbo.xp_cmdshell 'C:\PrintToPDFConsole.exe'

    Now the output is :

    NULL

    and the exe file does not run.

    Let me more clear about the exe file.

    I've a exe file developed using Visual Studio .Net 2005. It is a console application and it does not contain GUI.

    This application will convert any file(like .txt, .doc etc) to .pdf file.

    It has following code:

    using System;

    using System.Collections.Generic;

    using System.Text;

    using System.Diagnostics;

    namespace PrintToPDF

    {

    class Program

    {

    static void Main(string[] args)

    {

    try

    {

    Process printProcess = new Process();

    printProcess.StartInfo.FileName = "C:\\k.txt";

    printProcess.StartInfo.Verb = "print";

    printProcess.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;

    printProcess.StartInfo.CreateNoWindow = true;

    printProcess.Start();

    try

    {

    //printProcess.WaitForExit();

    }

    catch (InvalidOperationException ex)

    {

    throw ex;

    }

    printProcess.Dispose();

    }

    catch (Exception ex)

    {

    throw ex;

    }

    }

    }

    }

    Please note that I'm using Adobe Acrobat 6.0 Professional and PDF Printer is installed in my system and it is set to default printer. The default port is set to My Document\*.pdf .

    When I run the exe file, the 'k.txt' file getting converted to 'k.pdf' and save to My Document folder.

    Now please tell me what may be the possible errors.

    Is there any configuration problem in my sql server 2000?

    Please tell in detail that what is the configuration i need to change.

    Thank you.