A lightweight SQL query performance monitoring and profiling tool designed specifically for Classic ASP applications. SQLWatchdog helps developers identify slow queries, monitor SQL performance, and optimize database operations with minimal setup and overhead.
- 🔍 Zero-Configuration Monitoring: Simply wrap your existing connection with SQLWatchdog
- ⚡ Performance Tracking: Automatically tracks query execution times
- 🎯 Slow Query Detection: Configurable threshold for identifying slow queries (default: 500ms)
- 📊 Query Analysis: Detailed reports on query types (SELECT, INSERT, UPDATE, DELETE)
- 🛡️ Safe Connection Handling: Proper connection lifecycle management
- 🔄 Transaction Support: Full support for database transactions
- 📝 Query Logging: Comprehensive logging of all SQL operations
- 🎨 Built-in HTML Reports: Beautiful, styled performance reports
⚠️ Error Handling: Detailed SQL error capturing and reporting- 🔒 Parameter Safety: Automatic parameter type detection and safe handling
The built-in performance report shows:
- Query content with syntax highlighting
- Query type (SELECT, INSERT, etc.)
- Execution duration in seconds
- Status indicators (SLOW/OK)
- Highlighted slow queries for easy identification
- Include the SQLWatchdog in your ASP page:
<!-- #include file="sqlwatchdog.asp" -->
- Initialize SQLWatchdog with your existing connection:
' Create normal connection
Dim Conn, origConn
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open connectionString
' Replace with SQLWatchdog
Set origConn = Conn ' Keep reference to original connection
Set Conn = New SQLWatchdog ' Create proxy
Conn.SetConnection origConn ' Give original connection to proxy
Conn.SetThreshold 0.3 ' Set slow query threshold (300ms)
- Use normally - SQLWatchdog automatically monitors all queries:
Set rs = Conn.Execute("SELECT * FROM users")
' ... use recordset as normal ...
The diagram above shows how SQLWatchdog intercepts and monitors database operations:
- Your ASP application sends a query
- SQLWatchdog intercepts and starts timing
- Query is forwarded to the database
- Results are captured and analyzed
- Performance metrics are logged
The architecture diagram illustrates:
- SQLWatchdog acts as a proxy between your app and database
- Original connection is preserved and delegated to
- All queries are monitored and timed
- Performance data is collected and analyzed
- Reports are generated on demand
Associates the SQLWatchdog with an existing database connection.
Conn.SetConnection origConn
Sets the threshold for slow query detection in seconds.
Conn.SetThreshold 0.3 ' 300ms
Executes a SQL query with performance monitoring.
Set rs = Conn.Execute("SELECT * FROM users")
Executes a parameterized query safely.
Set rs = Conn.ExecuteParams("SELECT * FROM users WHERE id = ?", Array(userId))
Internally determines the type of SQL query:
- SELECT
- INSERT
- UPDATE
- DELETE
- OTHER
Automatically detects parameter types:
- Integer (vbInteger, vbLong)
- Double (vbSingle, vbDouble)
- Date (vbDate)
- String (vbString)
- Boolean (vbBoolean)
- Default: VarChar
Get the current connection state.
If Conn.State = 1 Then ' adStateOpen
' Connection is open
End If
Safely closes the database connection.
Conn.Close
BeginTrans()
: Starts a transactionCommitTrans()
: Commits current transactionRollbackTrans()
: Rolls back current transaction
Returns the last error message if any.
If rs Is Nothing Then
Response.Write Conn.GetLastError()
End If
Clears the query log history.
Conn.ClearLogs()
Generates an HTML report of query performance.
Response.Write Conn.RenderReport(True) ' Show all queries
The RenderReport
method includes built-in CSS styling:
- Clean table layout
- Highlighted slow queries
- Color-coded status indicators
- Responsive design
- Modern typography
Example Report Columns:
- Query content (HTML encoded for safety)
- Query type
- Duration (in seconds)
- Status (SLOW/OK)
The example
directory contains everything you need to test SQLWatchdog:
Edit example/db.asp
with your database settings:
Const DBdriver = "MySQL ODBC 3.51 Driver"
Dim DBname : DBname = "demo_test_db"
Dim DBuser : DBuser = "demo_test_user"
Dim DBpass : DBpass = "your_password"
Dim DBserver : DBserver = "localhost"
Dim DBPort : DBPort = "3306"
Run example/createtestdb.asp
to set up the test environment:
- Creates test database if not exists
- Sets up
users
andorders
tables - Populates tables with sample data
Tables Created:
users
(id, username, email, created_at, status)orders
(id, user_id, total, order_date, status)
Access example/usage.asp
to see SQLWatchdog in action:
- Simple SELECT query
- Slow query with JOIN (using SLEEP)
- Parameterized query
- Transaction handling
- Performance report generation
example/
├── createtestdb.asp # Database setup script
├── db.asp # Database connection settings
├── style.css # Modern styling for examples
└── usage.asp # Usage demonstrations
- Monitor Query Performance
' Set custom threshold
Conn.SetThreshold 0.3 ' 300ms
' Execute some queries
Set rs = Conn.Execute("SELECT * FROM users")
- Test Transaction Handling
Conn.BeginTrans
' ... perform multiple operations ...
If success Then
Conn.CommitTrans
Else
Conn.RollbackTrans
End If
- View Performance Report
' Show all queries including fast ones
Response.Write Conn.RenderReport(True)
' Show only slow queries
Response.Write Conn.RenderReport(False)
- Always Keep Original Connection Reference
' GOOD
Set origConn = Conn
Set Conn = New SQLWatchdog
Conn.SetConnection origConn
' BAD - Original connection lost
Set Conn = New SQLWatchdog
Conn.SetConnection Conn ' Don't do this!
- Proper Cleanup
' Clean up in reverse order
Conn.ClearLogs()
Conn.Close
Set Conn = Nothing
- Error Handling
Set rs = Conn.Execute(sql)
If rs Is Nothing Then
' Handle error
Response.Write "<p class='error'>" & Conn.GetLastError() & "</p>"
End If
- Download the latest release from GitHub
- Copy
sqlwatchdog.asp
to your project directory - Include it in your ASP pages where needed
- Classic ASP environment
- ADODB.Connection support
- Basic error handling capabilities
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
MIT License - see LICENSE file for details.
Anthony Burak DURSUN
- Email: badursun@gmail.com
- GitHub: badursun
Note: This tool is designed for development and debugging purposes. Consider your production environment's requirements before enabling in production.