views:

40

answers:

2

Is it possible to create a stored procedure that can call a function/generate C# code? I already know how to call a stored procedure from C# (I was surprised at how easy it is, I thought it'd be much more complex) but what I'm trying to do is have a stored procedure generate code based on certain information from SQL, but my problem for not being able to just use the information from SQL is I have to bounce it through iTextSharp to generate a report.

So if anyone knows if it's possible (And a tutorial/example, that'd be awesome) could they please shed some light on this? Again to just make it clear, I am hoping to use a stored procedure to either call a C# function or generate C# code on the fly in hopes of generating a PDF with iTextSharp.

Thanks!

Side note : As I was adding tags, I saw stored-functions, I don't have much experience but would they possibly work for what I'm looking to do as well?

+2  A: 

Yes it is possible to generate Stored Procedures that call C# code using the CLR. I'm not sure it's possible to generate C# code on the fly though since it's compiled code.

Heres a quick refrence for you: http://www.sqlteam.com/article/writing-clr-stored-procedures-in-charp-introduction-to-charp-part-1

Tim Meers
So from reading the tutorial (Briefly mind you) it sounds like this will let me make a stored procedure, deploy it and use it from SQL Manager/Call the SQL statement from, say, a website, correct?Not generating on the fly is fine mainly because I want to make a sproc to pass info in, and then use iTextSharp to generate a report based on the info passed in and some other things, and then call it from a webpage/SQL manager.Thanks again, hopefully it works as I'm thinking here
CSharpProgrammer
+1  A: 

You may be able to using SQL Server CLR Integration, have a read here for more info

w69rdy