Home arrow ASP arrow Page 3 - Using ASP & SQL To Ping A Remote Server
ASP

Using ASP & SQL To Ping A Remote Server


Using Microsoft SQL Server 2000 and some ASP script, Mitch creates a function that will ping any remote server, digest and process the results, and then return a summary of that ping session through an ASP function.

Author Info:
By: Mitchell Harper
Rating: 5 stars5 stars5 stars5 stars5 stars / 35
November 28, 2001
TABLE OF CONTENTS:
  1. · Using ASP & SQL To Ping A Remote Server
  2. · An overview of the procedure
  3. · Creating the stored procedure
  4. · The GetPingStats() ASP function
  5. · Analyzing the ping attempts
  6. · Conclusion

print this article
SEARCH DEVARTICLES

Using ASP & SQL To Ping A Remote Server - Creating the stored procedure
(Page 3 of 6 )

As mentioned above, our function will connect to the SQL server and execute the sp_PingServer stored-procedure. To create the procedure, fire up Query Analyser on the SQL Server, login, and enter the following commands into the query window:

USE MYDATABASE

GO

CREATE PROC sp_PingServer

@strServerIP VARCHAR(50)

AS

DECLARE @strCmd VARCHAR(60)

SELECT @strCmd = 'ping ' + @strServerIP

EXEC Master..xp_cmdShell @strCmd

GO


NB: This example creates the stored procedure in the "MYDATABASE" database. You should change this to match the name of your database.

If all goes well, Query Analyser will respond with:

The command(s) completed successfully.

Our newly created stored procedure, sp_PingServer, simply calls an extended stored procedure, xp_cmdShell, which is part of the master database.

Extended stored procedures do not reside in the database like other stored procedures. Instead, they are part of a library of DLL’s. Xp_cmdShell is part of the xplog70.dll library, typically located in the \Program Files\Microsoft SQL Server\MSSQL\Binn directory of the SQL Server.

The xp_cmdShell extended procedure takes one parameter, which is a windows shell command to be executed locally on the server. Any command or program that can be executed in a normal DOS prompt window, such as xcopy, dir, mem, ftp, del, etc can be passed as this parameter.

When our stored procedure is ran, it executes the command and returns the results. Each line returned by the command is added to the result set as a new row. Here is an example of running the stored procedure:

The result of executing sp_PingServer localhost

If you open a new DOS prompt window and execute the ping command against localhost (i.e. “ping localhost”), then you will see that the results are exactly the same.

Now that we’ve covered the details of creating the stored procedure that will actually execute the ping command for us, let’s create the ASP function, which will do all of the processing work.
blog comments powered by Disqus
ASP ARTICLES

- Central Scoreboard with Flash and ASP
- Calorie Counter Using WAP and ASP
- Creating PGP-Encrypted E-Mails Using ASP
- Be My Guest in ASP
- Session Replacement in ASP
- Securing ASP Data Access Credentials Using t...
- The Not So Ordinary Address Book
- Adding and Displaying Data Easily via ASP an...
- Sending Email From a Form in ASP
- Adding Member Services in ASP
- Removing Unconfirmed Members
- Trapping HTTP 500.100 - Internal Server Error
- So Many Rows, So Little Time! - Case Study
- XDO: An XML Engine Class for Classic ASP
- Credit Card Fraud Prevention Using ASP and C...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials