4

I have a SqlDataSource that calls a stored proc. When the page loads a Gridview loads that uses that SqlDataSource.

At this time I want to be able to debug the stored proc.

I DON'T want to debug the stored proc on it's own.

I want to see what values are actually being passed to the stored proc and what it is actually doing.

11
  • have you rights to recompile stored procedure? Commented Aug 30, 2010 at 14:47
  • if you have, you can create some table to log all input parameter values to this table. Commented Aug 30, 2010 at 14:48
  • Is there another way to find out what parameters are being passed to the SqlDataSource? Commented Aug 30, 2010 at 14:48
  • I do not have rights to recomplie stored procs. I have very little rights to do anything. I also cannot create tables. Commented Aug 30, 2010 at 14:49
  • 1
    Use local server (express edition for example, or developement) with ALTER TRACE or sysadmin rights to use SQL Server Profiler. Don't use table and don't change your stored procedure. Profiler traces all calls to the sql server with param values Commented Aug 30, 2010 at 15:07

2 Answers 2

4

Use Sql Server Profiler. You can listen all requests to your sql server if you have rights.

ADDED:

"SQL Profiler without sysadmin rights" or "this one" can help you.

Test your code on your own sql server(with sa rights), not production. If it works at your one it will work on production. Otherwise demand Trace rights to do to your job!

So, use a local server (express edition for example, or developer edition) with ALTER TRACE or sysadmin rights to use SQL Server Profiler. Don't use table and don't change your stored procedure. Profiler traces all calls to the sql server with param values. Just catch this calls!

ADDED:

I have found ADO.NET Trace Logging. I think, this is what you are looking for. On my opinion this tracer is not so good to use, but in your case, I think it can help.

Sign up to request clarification or add additional context in comments.

8 Comments

From the looks of it I would have to have waaaayyyy more privliges on the database than I do. I don't have admin access to the database. Don't even have rights to recomplie my procs as dbo.
you should not recompile stored procedure, but you have to have sysadmin rights to listen.
I was not suggesting that I recomplie the proc, I was just giving an example of how little rights I have. Sorry, this wont work.
Sorry igor, I'm not going to be able to get those permissions either. Is there any way to tell from the .net side what parameters are being passes to the stored proc?
I guess the answer is create a local version of the database, get the nessisary rights, or do what i'm going to do. Create a temp table and modify your stored proc to insert the parameters into the temp table along with a timestamp.
|
0

OK - this is not debugging exactly , but what you can do is put a break point in the ASP.NET where exactly you are about to call the Database ( command parameters is ready)

then go to immediate window and call this method

?DebugUtils.DebugStoredProc("Your stored procedure ",CommandObj); this will return you a string which you can directly copy and execute in Query Analyser.

public class DebugUtils
{
    public DebugUtils()
    {
        //
        // TODO: Add constructor logic here
        //




    }


    public static string DebugStoredProc(string spName, SqlCommand cmd)
    {
        //string szSPComand = string.Empty;
        string szSPComandFirstPart = "EXEC "+spName + "  ";
        string szSPComandSecondPart = string.Empty;
        string szDEBug = string.Empty;

        foreach (SqlParameter sqlparam in cmd.Parameters)
        {
            if (szSPComandSecondPart.Length > 0) { szSPComandSecondPart += " , "; szDEBug += " , "; }

            szSPComandSecondPart += string.Format("{0}={1}",sqlparam.ParameterName, ReturnParamToken(sqlparam));
            szDEBug += String.Format(" {0} ", sqlparam.ParameterName);
        }

        return szSPComandFirstPart + "  " + szSPComandSecondPart;
    }

    private static string ReturnParamToken(SqlParameter param)
    {
        string sToken = string.Empty;
        SqlDbType dbtype = param.SqlDbType;


        if (           dbtype == SqlDbType.Char 
                    || dbtype == SqlDbType.VarChar 
                    || dbtype == SqlDbType.Xml
                    || dbtype == SqlDbType.UniqueIdentifier     )
        {
            #region String - chars

            if (param.Value == DBNull.Value)
            {
                sToken = " null ";
            }
            else
            {
                sToken = "'" + FixQuotes(Convert.ToString(param.Value)) + "'";
            }

            #endregion

        }

        else if (
                        dbtype == SqlDbType.BigInt
                    || dbtype == SqlDbType.Decimal
                    || dbtype == SqlDbType.Float
                    || dbtype == SqlDbType.Int
                    || dbtype == SqlDbType.Money
                    || dbtype == SqlDbType.Real
                    || dbtype == SqlDbType.SmallInt
                    || dbtype == SqlDbType.SmallMoney
                    || dbtype == SqlDbType.TinyInt
                )
        {

            #region Numbers
            if (param.Value == DBNull.Value)
                    {
                        sToken = " null ";
                    }
                    else
                    {
                        sToken = Convert.ToString(param.Value);
                    }
            #endregion
        }

        else if (
                        dbtype == SqlDbType.DateTime
                    || dbtype == SqlDbType.DateTime2
                    || dbtype == SqlDbType.SmallDateTime
                    || dbtype == SqlDbType.Time
                    || dbtype == SqlDbType.Timestamp
               )
        {
            #region Dates
            if (param.Value == DBNull.Value)
                    {
                        sToken = " null ";
                    }
                    else
                    {
                        sToken = string.Format("'{0}'", Convert.ToString(param.Value));
                    }

            #endregion
        }
        else if (
                    dbtype == SqlDbType.Bit
                 )
        {

            #region BIT or BOOL

            if (param.Value == DBNull.Value)
            {
                sToken = " null ";
            }
            else
            {
                if (Convert.ToBoolean(param.Value) == true)
                {
                    sToken = "1";
                }
                else
                {
                    sToken = Convert.ToString(param.Value);
                }

            }

            #endregion

        }
        else if (
                        dbtype == SqlDbType.Binary

                    || dbtype == SqlDbType.Date

                    || dbtype == SqlDbType.DateTimeOffset

                    || dbtype == SqlDbType.Image

                    || dbtype == SqlDbType.NChar
                    || dbtype == SqlDbType.NText
                    || dbtype == SqlDbType.NVarChar



                    || dbtype == SqlDbType.Structured
                    || dbtype == SqlDbType.Text

                    || dbtype == SqlDbType.Udt

                    || dbtype == SqlDbType.VarBinary
                    || dbtype == SqlDbType.Variant
             )
        {
             if (param.Value == DBNull.Value)
            {
                sToken = " null ";
            }
            else            
            {
                sToken = string.Format("UNKNOWN DATATYPE - NO HANDLER FOUND for @param : {0} of datatype:{1} ", param.ParameterName, Convert.ToString(dbtype.ToString()));
            }


        }

        return sToken;
    }

    private static string FixQuotes(string str)
    {
        return str.Replace("'", "''");
    }


}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.