Auto insert and check if website is live?

Posted on 2006-06-01
Last Modified: 2011-10-03

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?

Question by:paulwhelan
    LVL 13

    Expert Comment

    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.

    Author Comment

    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

    Author Comment

    "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?


    Author Comment

    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?

    LVL 13

    Accepted Solution

    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

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
    JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
    Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
    Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now