views:

143

answers:

1

Is there a straight forward way to view the SQL command text actually executed against the underlying database by a DbCommand object (i.e. after the parameters have been processed into a statement)?

Here the detail: I'm using VB.Net 3.5 and have a factory object (DbProviderFactory) and a connection (System.Data.IDbConnection). I am using the factory to create a new command object using the DbProviderFactory.CreateCommand() method and then assigning a parametrized query to the CommandText property of the command. Later on I create and associate some parameters with the query (created using the DbProviderFactory).

This is great, but I want to get a look at the actual SQL statement generated by the command object. I am currently testing this against a SQLite database, but wondered if there were a general approach which would work.

+1  A: 

The actual SQL executed by the server is exactly what you wrote. The parameters are sent separately from the command itself, so they're actually never replaced with their value in the SQL command.

Thomas Levesque
Thanks Thomas - I guess I didn't understand the way this works. So the database API is used to do the binding behind the scenes.
AJ