Can you execute a VB.NET .exe from within SQL?

  • We need to execute a VB.NET (2010) executable from SQL (2005).

    Is this possible, and what is the best way to do this?

  • N11689 (8/14/2012)


    We need to execute a VB.NET (2010) executable from SQL (2005).

    Is this possible, and what is the best way to do this?

    I guess this might work: -

    EXEC master..xp_CMDShell 'c:yourFile.exe'


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • It should be noted that xp_cmdshell is disableb by default in SQL Server (since 2005) and for good reason. Consider carefully before enabling it the security implications. Do you want all sysadmins to be able to interact with the cmd shell on your server?

    Resist the urge to turn your SQL Server into an application server. Ask yourself it you really need to execute an app from within T-SQL. From my perspective a design that requires that T-SQL must have access to interact with the file system raises several huge red flags. Another way to do this would be to create a SQL Agent job with a CmdExec step that runs the executable and then start the job from T-SQL using msdb.dbo.sp_start_job (note that sp_start_job is asynchronous).

    Ultimately my preferred way to do something like this would be to refactor the T-SQL into two stored procs, a before and after, split at the point where you would call the app. Then using PowerShell, SSIS, C# or some other app development language call the before proc, then call your VB.net executable, then call the after proc.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • From what I have 'googled', I don't think we want to use xp_cmdshell.

    What about SQL CLR? Can you call a vb.net exe (not dll) using an SQL Assembly?

  • N11689 (8/14/2012)


    From what I have 'googled', I don't think we want to use xp_cmdshell.

    What about SQL CLR? Can you call a vb.net exe (not dll) using an SQL Assembly?

    Sure, but I think you'll need to mark the assembly UNSAFE which is a red flag in and of itself. Again, ask yourself why you're in this spot. My recommendation is to refactor your process such that you do not need to call an executable directly from T-SQL. If you must, see my earlier post on how to accomplish it indirectly using SQL Agent.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • We have a new app that needs to automatically create a pdf and email it.

    We will be writing a new Crystal Report that will call a sql stored procedure that contains the data necessary to create this .pdf file.

    We have an existing vb.net program that uses SAP Crystal Reports' object to generate and output a report (using the Crystal for .NET methods and properties).

    We want our app to call this vb.net executable via SQL.

    Just trying to find the best approach for this.

  • N11689 (8/14/2012)


    We have a new app that needs to automatically create a pdf and email it.

    We will be writing a new Crystal Report that will call a sql stored procedure that contains the data necessary to create this .pdf file.

    We have an existing vb.net program that uses SAP Crystal Reports' object to generate and output a report (using the Crystal for .NET methods and properties).

    We want our app to call this vb.net executable via SQL.

    Just trying to find the best approach for this.

    My preferred approach would be to have your app call the vb.net exe directly, i.e, leave SQL out of the report-generation stack...else use SQL Agent.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • Our app resides on a different server than the vb.net exe. The vb.net exe is on the sql server.

    I'll take this info you've provided and bring it to the group and see how we will proceed.

  • You can execute a vb.net app from a network location. If you were to post the vb.net app on a file server where all people who needed it could reach it they could execute it from there.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply