Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 340
  • Last Modified:

Auto insert and check if website is live?


I know that I can check if a website is 'live' by doing this in C#

HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(websiteToRequest);
            webRequest.Timeout = 6000;
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
string responseStream = webResponse.GetResponseHeader("Content-Length");

But does anyone know how to set up a scheduled task to check if a site is 'live'
and then insert into a table in my sql server database to say if its live or not?

  • 3
  • 2
1 Solution
Well you could compile that code and execute it as a SQL Job...

Change your code to add a SQL Server connection string and insert the results into SQL.
paulwhelanAuthor Commented:
BTW I just tried saving this

strConnection = "Data Source=PC024\\PAUL;Initial Catalog=paulstest;Integrated Security=True;";  
set objConn  =  CreateObject("ADODB.Connection")
objConn.Open strConnection
Set objRS    = CreateObject("ADODB.Recordset")

SQL = "INSERT INTO websitestatistics(id, checkeddate, didreply) " & _
      "VALUES ('1', '" & NOW() & "', 'n')"
set objRS = objConn.execute(SQL)

to a file 'scheduled.vbs'
and added a scheduled task
but when it ran it threw an error

windows script host
expected end of statement
paulwhelanAuthor Commented:
"Well you could compile that code and execute it as a SQL Job...

Change your code to add a SQL Server connection string and insert the results into SQL."

How would I do that?

paulwhelanAuthor Commented:
ok I see it in Enetrprise Manager
Job Scheduling

Is it possible to check if the site is live and then do an insert to the database with a visual basic script?
If so how?

I would ask that in the VB forum. I don't know your site  or anything about it..

Basically all you have to do is make your code do it's check to see if the site is live. Maybe assign a 0 or 1 to a variable 0 for dead, 1 for live. Then have the code make a connection to SQL with a connection string of your choosing, and have that variable placed into the appropriate table in SQl using an insert statement. Maybe also add the current datetime stamp something like

"INSERT INTO TABLENAME (StatusCode, DateOfCheck) VALUES ("+varName+",getdate())"

I am not a VB programmer so my syntax is probably wrong up there, but you should get the point.

Then you can schedule that as a job (you can change your step type to be execute OS command, and put the path to your compiled exe, your .bat that contains the running of the .vbs/ etc. etc.

Then you can schedule that job to run on a regular basis..

the only question is what do you want to do with this info? Do you want to just keep track of it, do you want an alert if a 0 is in there, etc. etc.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now