0

I have an asp.net mvc application that take a while to load on my production server. I would like to write a script to call my pages every 10 minutes to avoid the pages from being scrapped on the server, which would then cause the server to reload them.

I was thinking of using a SQL Server stored procedure to call my pages every 10 minutes to keep the pages alive.

I've read that I can do this using CLR, but I am not sure how. Does anyone have an example of how to call webpages in a SQL Stored Procedure using CLR?

3 Answers 3

6

I have no idea why you would want to use a stored procedure for this.

Just write a simple console application to "call" the page. Then use a scheduled task to run the console application.

Sign up to request clarification or add additional context in comments.

1 Comment

I went ahead and built a windows service application to do this.
1

Code untested but something like this should work.

You'll probably also need TRUSTWORTHY SET.

ALTER DATABASE Foo SET TRUSTWORTHY ON;

Code:

public partial class WebProc
{
   [SqlFunction()]
   public static string WebQuery()
   {
      WebRequest request = HttpWebRequest.Create("http://www.google.com");
      WebResponse response = request.GetResponse();
      Stream dataStream = response.GetResponseStream();
      StreamReader reader = new StreamReader (dataStream);
      string responseFromServer = reader.ReadToEnd();
      return responseFromServer;
   }
}

3 Comments

-1: especially inside of SQL Server, I think you'd better put response, dataStream, and reader inside of using blocks.
@John. Sure the code can be made safe. This was merely to illustrate the "How do I" question. As I'm not answering the "Should I question".
far too many developers copy / paste what they see on SO and elsewhere. Fix the code and I'll remove the downvote.
0

I have no idea why you would want to use a stored procedure for this.

Just write a simple console application to "call" the page. Then use a scheduled task to run the console application.

You could do that (of course) but that's not what the question was asking ;)

Jafin's answer is correct for the question.

The best answer (IMHO) would be to fix your production server (i.e. reconfigure the settings) so that it doesn't "scrap" your pages every 10 minutes.

Why use a jackhammer (console app or .net inside the database or whatever) when a regular one will do?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.