title: Classic ASP + ADODB -- how to see actual query being run (for testing)
body: <p>I'm using Classic ASP.  I have a wrapper function for database queries that accepts a query string and an array of parameters, and auto-creates the proper query object and runs the query.  Very handy and has been working great.</p>
  
  <p>Here's my problem:  When testing, I often want to see the exact text of the query being passed to SQL.  Back in the "bad old days" of assembling queries through concatenation I could just write out the string.  Now that I'm using parameterization it's a bit more tricky.</p>
  
  <p>How do I take a peek at the fully-assembled query string just before it's passed to the database connection?</p>
  
  <p>Here is the function I'm using, simplified. (The actual function doesn't assume string, for example.)</p>
  
  <pre><code>Public Function pquery( strQuery, params )
      Dim cmd, param, thisParam, rs
      Set cmd = Server.CreateObject( "ADODB.Command" )
      cmd.ActiveConnection = MyConn
      cmd.CommandText = strQuery
      If IsArray( params ) then
          Dim adVarChar : adVarChar = 200
          For Each param In params
              Set thisParam = cmd.CreateParameter( "@p", adVarChar, , len( param ), param )
              cmd.Parameters.Append thisParam
          Next
      End If
      Set rs = cmd.Execute
      Set pquery = rs
  End Function
  </code></pre>