c# - Intercept the query that SqlCommand executes on the database -


is somehow possible intercept query given sqlcommand going execute on database?

i'd track debugging purposes queries data class invokes, , can't find clever way this.

i tried use weird "replace" of sql command string, or appending parameters funky

sb.appendline("@" + p.parametername + " = " + p.todebugstring()); 

(with "todebugstring()" being extension method "tostring()" or without single quotes depending if it's string or not)

but seems kinda unprofessional, , fails horribly when encounters an

sqldbtype.structured 

parameter.

more or less, i'd intercept db call inside application in same way sqlserver profiler inside db itself.

thank in advance.

big edit:

i know given simple query this:

select * mytable id=@id 

rather running this:

select * mytable id=1234 

the database runs procedure this:

declare @id int set @id = 1234 select * mytable id=@id 

can intercept @ application level last block?

it sounds you're wanting see parameters substituted directly in query string "as it's done on server". not possible, because server never substitutes parameters string. that's beauty of parameterized queries: data data, code code, , never twain shall meet.

given simple query this:

select * mytable id=@id 

rather running this:

select * mytable id=1234 

you can think of if database runs procedure this:

declare @id int set @id = 1234 select * mytable id=@id 

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -