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
 General SQL Server Forums
 New to SQL Server Programming
 Storing the result of a C# program in a SP var

Author  Topic 

im1dermike
Posting Yak Master

222 Posts

Posted - 2008-12-11 : 11:22:14
Is it possible to store the result of a C# console application in a stored procedure variable? This doesn't work obviously, but this is effectively what I'm trying to do:
set @prog = 'C:\program.exe "param1" "param2"'
set @var = exec xp_cmdshell @prog


The C# program.exe returns a string.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-11 : 11:59:00
seem like what you need is dynamic sql

something like

declare @sql varchar(8000)
set @prog = 'C:\program.exe "param1" "param2"'
set @sql='exec xp_cmdshell '+@prog

sp_executesql @sql,'@prog varchar(100)',@prog
Go to Top of Page

im1dermike
Posting Yak Master

222 Posts

Posted - 2008-12-11 : 12:13:07
Sh*t. Road block. I know this isn't a SQL issue, but the only valid return type for main function is int? So I can't create an app that returns a value?

The only solution as I see it now to keep my C# program non-specific to this application is to create a SQL table and just load my results into that table, then access the records in my SQL sp.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-11 : 12:18:05
you need to use OUTPUT variables for that and return values through it

http://www.sqlteam.com/article/stored-procedures-returning-data
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2008-12-11 : 12:24:21
quote:
Originally posted by visakh16

you need to use OUTPUT variables for that and return values through it

http://www.sqlteam.com/article/stored-procedures-returning-data




That's assuming they are actually calling a sproc...which I don't think they are

but that would be the answer



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -