简体   繁体   English

捕获ADO.net DB查询运行时

[英]Capturing the ADO.net DB queries run-time

I am trying to capture the Db query for this below piece of C# .net Web application. 我正在尝试捕获下面这个C#.net Web应用程序的Db查询。

There are way to do if i use DbProviderfactory by making a proxy of it. 如果我通过代理它来使用DbProviderfactory,还有办法。 But instead of using a DbProviderFactory if i use SqlConnection and SqlCommand directly like below , how can i trace my DB calls ? 但是,如果我直接使用SqlConnection和SqlCommand,而不是使用DbProviderFactory,如何跟踪我的数据库调用?

            SqlConnection myConn = new SqlConnection(@"Server=192.168.23.99;Initial Catalog=cat1;User ID=user21;Password=userpwd");
            SqlCommand myCommand = new SqlCommand("select * from table1", myConn);
            SqlDataReader dataReader;

            System.Threading.Thread.Sleep(5000);
            try
            {
                myConn.Open();
                dataReader = myCommand.ExecuteReader();

                GridView1.DataSource = dataReader;
                GridView1.DataBind();
                dataReader.Close();
                myCommand.Dispose();
                myConn.Close();
            }
            catch (System.Exception ex)
            {
                Response.Write(ex.ToString());
            }

I am aware that there are profilers to trace this. 我知道有一些分析器可以追踪这个。 But , I want to do this in my program of my own. 但是,我想在我自己的程序中这样做。

Basically i need to profile the Db Connection and Db commands in a web request, Which does not use DbProviderFactories in it. 基本上我需要在Web请求中分析Db连接和Db命令,其中不使用DbProviderFactories。 I am new in developing profilers for .Net , so i expect some guidelines to do this. 我是开发.Net的分析器的新手,所以我希望有一些指导方针可以做到这一点。

Thanks. 谢谢。

Easy, just run SQL Profiler, and when you step over the myCommand.ExecuteReader() line, watch what SQL gets run in the profiler. 简单,只需运行SQL事件探查器,当您跨过myCommand.ExecuteReader()行时,请查看在事件探查器中运行的SQL。

For more info, see: https://msdn.microsoft.com/en-us/library/ff650699.aspx 有关详细信息,请参阅: https//msdn.microsoft.com/en-us/library/ff650699.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM