Auto insert and check if website is live?

Hi

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?

Thanks              
paulwhelanAsked:
Who is Participating?
 
MikeWalshCommented:
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.
0
 
MikeWalshCommented:
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.
0
 
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
0
 
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?

Thanks
0
 
paulwhelanAuthor Commented:
ok I see it in Enetrprise Manager
Tools
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?

Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.