none
Got "System.Data.SqlClient.SqlCommand:ExecuteReader" twice in JITCompilationStarted function. RRS feed

  • Question

  • I am seeing something weird my .Net Web application. 

    The below is my code

                SqlConnection myConn = new SqlConnection(@"Server=192.168.2.2;Initial Catalog=sss;User ID=dsd;Password=sdd");
                SqlCommand myCommand = new SqlCommand("select * from sss.ALARM", myConn);
                SqlDataReader dataReader;
    
                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());
                }

    While this application get attached to my .Net profiler that have set Jit Compilation event mask, I am getting two "System.Data.SqlClient.SqlCommand:ExecuteReader" calls in JITCompilationStarted function.

    But there is only one Executereader used. What is the reason for this ?

    Thanks

    -Selva



    • Edited by Selva VS Wednesday, February 11, 2015 6:51 AM
    • Moved by Fred BaoModerator Thursday, March 19, 2015 10:26 AM Moved from .NET Class Libraries
    Wednesday, February 11, 2015 6:51 AM

All replies

  • I can think of two situations that can cause this callback to be raised multiple times for the same method.

    • Some methods may need to be jitted multiple times due to different generic type arguments (on the type or method) in this situation the FunctionID will be different but the metadata token will be the same. Clearly this is not what's happening as neither SqlCommand nor ExecuteReader is generic.
    • If two threads try to access a method at the same time, they may both trigger the JIT and associated callbacks. I believe in this situation, both calls will be for the same FunctionID (this is touched on in the remarks section of the JITCompilationStarted and some other JIT related callbacks).

    In any case, the profiler is expected to produce the same IL sequence for the same metadata token no matter how many times the callback is called (unless re-jitting).

    Wednesday, February 11, 2015 9:36 AM
  • Brian, your points are valid.. but here i am not using two different threads .. This is single threaded application.. But also i am getting the calls twice.. 

    All the calls regarding to databases. Even Open() method is called twice. 

    Is there any property in ADO.Net that when you call <dbconnection>::Open() function , more than one managed threads will try to connect where only one will succeed..? 

    Thanks

    Selva

    Wednesday, February 11, 2015 10:36 AM
  • Does the the second call to JITCompilationStarted occur before or after the first call to JITCompilationFinished?

    Does GetCurrentThreadID report the same value in each case? (just to double check)

    Try setting a breakpoint in the callback and checking the stack for any reentry.


    Wednesday, February 11, 2015 11:34 AM
  • Both the functions have different function ID and same thread id..! But only the first function takes time to complete(by seeing its time taken to complete) where the later functions completes soon after they called. 

    And, The second function comes to JitCompilationStarted after the JitCompilationFinished callback for 1st function

    Eg: If 1st called takes 31 ms , the second function takes 0 ms

    If there are for connections to Open() .. My injected helper functions too are getting called twice for each Open() functions , which means the Open() function itself is getting called twice for each connection open.

    If there are 4 connections to open the below are number of calls,

    2 calls in my JITCompilationStarted

    8 calls to my injected helper function from Open(..) ( 2 for each connection open )

    Thanks

    -Selva

    • Edited by Selva VS Thursday, February 12, 2015 5:34 AM
    Thursday, February 12, 2015 4:36 AM
  • Brian, Is there any other suggestions ? 

    Please let me know if i my details are not clear.

    • Edited by Selva VS Thursday, February 12, 2015 9:00 AM
    Thursday, February 12, 2015 9:00 AM
  • I'm afraid I'm running low on ideas, all I can suggest is double check everything.

    The sort of things I would check in your situation include (in increasing order of desperation):

    • Do both FunctionIDs report the same ModuleID and metadata token?
    • Examine the exact bytes passed to SetILFunctionBody to ensure they match the expected IL.
    • Do both calls into your helper method have the same stacktrace from Open() (including native offsets)?

    When you said there were two different FunctionIDs involved, my first thought was that there are two 'Open' methods with different signatures and one calling the other (and your helper code being injected into both), but (at least on my computer running .NET4) there is only one 'Open' method.


    Thursday, February 12, 2015 9:55 AM
  • Can you please suggest any way to debug the Profiler ?? 

    My OS is Windows 8 64 bit Arch.

    -Selva

    Thursday, February 12, 2015 12:32 PM
  • Attach a native debugger (visual studio and windbg both work) to the process being profiled (probably w3wp.exe), set the breakpoint in the callback and make the page request.
    Thursday, February 12, 2015 1:37 PM
  • Just to tell u that , it dint work out.. If the Profiler is compiled in debug mode , some crash happens to the web application when a request in made. 
    Friday, February 13, 2015 7:17 AM
  • Hello Selva,

    You could have a try to debug with the .NET source according to this blog:

    http://blogs.msdn.com/b/dotnet/archive/2014/02/24/a-new-look-for-net-reference-source.aspx

    To see if you could find the caused reason.

    Regards


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, February 16, 2015 10:02 AM
    Moderator