Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 How to run .exe from T-sql

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-01-01 : 23:26:00
Marko writes "Hi,

How can i run Visual Basic exe or dll from T-sql. Something like this.


declare @ExSTR nvarchar(100) ,
@arg1 char(20), @arg2 char(20) ,@arg3 int, @arg4 int,@arg5 int, @arg6 int,@arg7 int
declare @arg8 datetime, @arg9 char(20), @arg10 char(20), @arg11 char(20), @arg12 char(20),@r float


select @ARG1 = 'gggg'
select @ARG2 = 'hhhh'
select @ARG3 = '123'
select @ARG4 = '582'
select @ARG5 = '125'
select @ARG6 = '156'
select @ARG7 = '46'
select @ARG8 = '2001-12-26'
select @ARG9 = 'true'
select @ARG10 = ''
select @ARG11 = ''
select @ARG12 = 'true'

set @ExSTR = N'c:\total1.exe'

execute @exstr, N'@arg1 char,@arg2 char, @arg3 int,@arg4 int,@arg5 int,@arg6 int,
@arg7 int,@arg8 datetime, @arg9 char,@arg10 char,@arg11 char,@arg12 char,@r float output'

print @r"

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2002-01-01 : 23:30:38
Hi

the extended stored proc xp_CmdShell will do this for you.
But be careful with it, your performance will suck if this is a long running EXE.



Damian
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2002-01-02 : 09:37:30
You can run it using xp_cmdshell. You can create an execute string to pass the arguments as command line parameters and retrieve them in the exe.
Getting @r bach is a bit more difficult though.
The app could write it to a table then you could retrieve it afterwards.
Otherwise you would have to create a com application and use the sp_oa... stored procs to run it.

==========================================
Cursors are useful if you don't know sql.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -