views:

38

answers:

2

Hi! I have procedure on SQL Server! Now,is it possible to create dll from that procedure and if it is, how i can do that?

Thanks!

+4  A: 

It is not possible to create a dll from a stored procedure - SQL Server stores the procedure internally as text (more or less), and only parses it into executable instructions on an as-needed basis.

Why is it that you wish to create a dll from a stored procedure?

  • SQL Server is capable of running code contained in .dll files in the form of CLR extensions - is this what you mean?
  • If you wish to obfuscate your stored procedure once it is installed then you can encrypt your stored procedure (however you still need the plain text version in order to create or update the stored procedure initially)

Update: As I understand it you have some code written in the form of a stored procedure that you wish to be able to call from code. If this is the case then you have two options:

  1. Port the code to another environment (e.g. C#, C++)
  2. Make the stored procedure available in an SQL server instance somewhere and call the code using normal SQL methods.

Option 1 is cleaner, however introduces the risk that you might not port the code correctly (and means that you may now have to maintain the same code in 2 different places - you might be able to get around this however by using CLR extensions, or re factoring your code)

Option 2 is simpler, however comes at the cost of a performance overhead, plus the added complication of ensuring that the SQL server instance is always available.

Without knowing more about what the stored procedure does my advice would probably be to go with option 1, as it will probably give you the least headaches in the long run.

Kragen
I just wont to put code from stored procedure in DLL! I need to call dll instead SQL server procedure!
@user238271 - and Kragen just told you, you can port the code into a C#/C++ (or even VB.NET, VB6, whatever) DLL. You *can't* create a DLL from a stored procedure.
LittleBobbyTables
+2  A: 

No, it is not possible to create a DLL from a stored procedure.

It is possible to call a DLL (both COM and CLR), when certain options are turned on.

Perhaps you could explain what you are trying to achieve?

Mitch Wheat
I just wont to put code from stored procedure in DLL! I need to call dll instead SQL server procedure!