Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4016542
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:45:09+00:00 2026-05-20T09:45:09+00:00

Is it somehow possible to intercept the query that a given SqlCommand is going

  • 0

Is it somehow possible to intercept the query that a given SqlCommand is going to execute on the database?

I’d like to track for debugging purposes all queries that my Data class invokes, and can’t find a clever way to do this.

I tried to use some weird “replace” of the sql command string, or appending the parameters with a funky

sb.AppendLine("@" + p.ParameterName + " = " + p.ToDebugString());

(with “ToDebugString()” being an extension method that does a “ToString()” with or without single quotes depending if it’s a string or not)

But that seems kinda unprofessional, and it fails horribly when it encounters an

SqlDbType.Structured

parameter.

More or less, I’d like to intercept the DB call inside the application in the same way the SqlServer Profiler does inside the DB itself.

Thank you in advance.

BIG EDIT:

I know that given a simple query like this:

SELECT * FROM MyTable WHERE ID=@ID

Rather than running it like this:

SELECT * FROM MyTable WHERE ID=1234

The database actually runs the procedure like this:

DECLARE @ID int
SET @ID = 1234
SELECT * FROM MyTable WHERE ID=@ID

Can I intercept at application level this last block?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T09:45:10+00:00Added an answer on May 20, 2026 at 9:45 am

    It sounds like you’re wanting to see the parameters substituted directly in the query string “as it’s done on the server”. This is not possible, because the server never substitutes the parameters into the string. That’s the beauty of parameterized queries: data is data, code is code, and never that twain shall meet.

    Given a simple query like this:

    SELECT * FROM MyTable WHERE ID=@ID
    

    Rather than running it like this:

    SELECT * FROM MyTable WHERE ID=1234
    

    You can think of it as if the database actually runs a procedure like this:

    DECLARE @ID int
    SET @ID = 1234
    SELECT * FROM MyTable WHERE ID=@ID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it somehow possible on Swing to set a TitledBorder transparent so that a
Is it possible somehow to close StreamReader after calling ReadToEnd method in construction like
I'm wondering, is it possible to somehow map a key-press event to act like
Is this possible somehow? @Name(geolocationService) public interface GeolocationService { @Query(SELECT g FROM Geolocation geolocation
Is it possible to somehow listen to all perforce cammands issued from my machine
Is it somehow possible to test warnings i Ruby using RSpec? Like this: class
Is it somehow possible to create a solr document that contains sub-elements? For example,
Is it somehow possible? I want that to enable compile-time passing of arguments. Suppose
is it somehow possible to call a rails function or to access a rails
Is it somehow possible to customize or subclass System.Windows.Forms.ColorDialog to add a few buttons?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.