locked
how to debug a sqlCommand? RRS feed

  • Question

  • User-1829411134 posted

    How to test @au_lname's value sends to the following following sql command?

    Dim MyCommand As New SqlCommand("UPDATE [authors] SET [au_lname] = @au_lname",  MyConnection)MyCommand.Parameters.Add(New SqlParameter("@au_lname", SqlDbType.NVarChar)).Value = me.au_lname.text

    I tried to print the "MyCommand.CommandText.ToString" but only get UPDATE [authors] SET [au_lname] = @au_lname with no value in the command text.

    Thanks!

     

    Tuesday, March 7, 2006 5:52 PM

All replies

  • User-1804824805 posted
    Use SQL Profiler, where you can see the value being sent.
    Tuesday, March 7, 2006 6:40 PM
  • User-1893879114 posted

    Unfortunately Profiler only comes with full version of Sql Server...

    You can also debug stored procedures using Visual Studio - see [url=http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsdebug/html/vxtskdebuggingsqlstoredprocedures.asp]this MSDN article[/url].

    Tuesday, March 7, 2006 6:55 PM
  • User390817712 posted

    1. Put the cursor on the line of code with the new SqlParameter. Drop a breakpoint on the line by pressing F9 (Debug -> Toggle Breakpoint).

    2. Start the debugger running with F5 (Debug -> Start Debugging).

    3. When the debugger breaks on your line of code that creates the parameter, press F10 to step to the next line (Debug -> Step Over).

    4. Open a Watch window with Ctrl+Alt+W (or Debug -> Windows -> Watch from the menu).

    5. In the watch window type in MyCommand. You can click through the object and drill into the parameters. You could also enter MyCommand.Parameters(0).Value to go straight to the value you want to see.

    I have some other debugging tips in an article: Basic Debugging Features In Visual Studio 2005. Most of this also applies to 2003.

    Wednesday, March 8, 2006 9:44 AM
  • User-1804824805 posted

    The original question does not specify SQL Server version or edition, however, as a developer, I would find a way to spring for the developer's edition, which used to be about US$45 for SQL 2000, and is worth every penny.

    That said, generally placing a breakpoint on the line where the parameter is set will help you figure out what is really being sent...

    Wednesday, March 8, 2006 10:14 AM
  • User-1587907100 posted

    This one is good. i was not knowign this.

    Wednesday, November 13, 2013 3:00 AM