Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi
I want insert code asp.net between <% %> in a sqlserver database and i wana write it in a page.aspx and execute it
thank's
for example
<%
String body="<% Response.Write(\"Hello world\") %>";
Reponse.Write(body);
%>

In output i want this result

Hello world 

not

<% Response.Write(\"Hello world\") %>;
Posted
Updated 19-Jan-11 5:31am
v2
Comments
Nish Nishant 19-Jan-11 11:30am    
You cannot run ASP.NET scripts inside SQL Server. Perhaps you can explain what it is that you are trying to accomplish here?
Sergey Alexandrovich Kryukov 19-Jan-11 11:31am    
John, say "Google is your friend" again...

I doing a bit of guessing here but I think you really meant to say you want to have code in text form inside the database and then include that code in your aspx page by placing it inside <%; %> tags.

Given the above assumption holds true I can tell you that: Yes it can be done, but it comes at a cost. Every time you wanted to change the inserted code on an aspx page you would have to run another page that initiates the changes by rewriting the content of the aspx file and after the rewrite you could redirect to that page and that is where the pain begins:
ASP.NET realizes that a change has been made to the file and needs to recompile it which takes some time. This can be tolerable if the changes are seldom even though it still is a scenario I'd rather not think about. You can clearly forget about it if the code changes are due on every page request.

Please consider using this library though: FLEE Fast Lightweight Expression Evaluator[^]. This fantastic library lets you compile expressions on the fly and then call them dynamically. Since the source code for the expressions is plain text you can keep them in your database and load them dynamically to compile and execute. For performance reasons you should consider some kind of caching for the compiled bits though as this process also introduces some overhead. The best part is of course that it executes as fast as normally compiled code.

I hope this was helpful to you. If you have any questions leave me a comment.

Best Regards,
Manfred
 
Share this answer
 
v3
Comments
fjdiewornncalwe 19-Jan-11 14:45pm    
A very thoughtful response to a very vague question. Well Done.
Espen Harlinn 19-Jan-11 16:02pm    
I agree with Marcus - nice piece of deduction, 5+
achekraali 20-Jan-11 9:43am    
thank's manfred it's a very good answer
i wanna stock page code into database like joomla in php
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900