If there is an easy way to get a complete SQL statement after changing parameters? Ie, I want to save the entire SQL log file that this program runs.
Or, if I want to do this, I just want to get rid of the parameters and execute the whole request in the old school uniform in one big line?
A simple example: I want to capture the output:
SELECT subcatId FROM EnrollmentSubCategory WHERE catid = 1
.. from this code:
Dim subCatSQL As String = "SELECT subcatId FROM EnrollmentSubCategory WHERE catid = @catId" Dim connectionString As String = "X" Dim conn As New SqlConnection(connectionString) If conn.State = ConnectionState.Closed Then conn.Open() End If Dim cmd As New SqlCommand(subCatSQL, conn) With cmd .Parameters.Add(New SqlParameter("@catId", SqlDbType.Int, 1)) End With Console.WriteLine("Before: " + cmd.CommandText) cmd.Prepare() Console.WriteLine("After: " + cmd.CommandText)
I assumed that Prepare () will do the replacements, but apparently not.
Thoughts? Advice? Thanks in advance.
Bryan source share