C # How to add code to execute in runtime

I know that this requirement may seem to many of you, but this is one of my project requirements. Is it possible to add code to Sp and execute in .Net exe. As with a button click, I call one SP, which SP returns a few lines of code, and then executes the code.

Is it possible, if so, how?

I am using framework 1.1

+2
reflection c #
source share
4 answers

Searched for "dynamic execution of C # code", and Google came up with this blog since 2002 ... This might work for you.

http://www.west-wind.com/presentations/dynamiccode/dynamiccode.htm

The article mentions System.CodeDom.Compiler to compile the assembly on the fly, and then use Reflection to execute this code. Sounds like fun;)

EDIT: As DaveL suggested: Is it possible to dynamically compile and execute C # code snippets?

+3
source share

If you are talking about compiling TSQL into a table, and then running that TSQL later through C #, yes, it is possible. You will need to write a simple parser for TSQL script files (.sql). The analyzer will read the SQL script and in each GO statement will add the TSQL statement to the corresponding SQL Server table (the table can have two columns 1. Database to run against / process name to run against. 2. Query itself.). Then you can execute these TSQL blocks dynamically at runtime.

If you are talking about starting C #, which was compiled into a SQL Server data table, this is a great ball game, and I don't know how to do it (this is possible at all).

Hope this helps.

+1
source share

Another possibility:

Using several varbinary binary data as a database, you can store assemblies in a table as binary data. You can then read this binary data from the database, save it locally, load the assembly through Assembly.LoadFrom() , and then use reflection to find some special types or entry points that you could use.

+1
source share

You probably want DLR (where D stands for Dynamic), unfortunately this is .NET 4.0 up.

It looks like you are in the terrible legacy code of netherworld; rather you than me.

You can create your own scripting language to run in your application, but it will be slow and not ideal. Something like YACC will make you part with it, but this is an uneven ride (if anyone tries to do this in Java).

0
source share

All Articles