sql-serversql-server-profiler

SQL Server Profiler trace different result on different system for same query


I run same JAVA application (spring/hibernate) on different system both use same SQL Server version.

I'm using SQL Server Profiler to trace a query which I run (exactly same) on both systems.

This is my SQL Server version on both system: enter image description here

It seems here on slow-screenshot a query of "use database" takes "331ms" compared to fast.trc (0ms= : enter image description here

What can cause this difference just by running "use database" query ?

I tried on a 3th system running on sql express which is too slow here is trace

It seems here on "sql express" it is due to the fact I have two additional classEvent Audit Logout that takes time : enter image description here

Maybe I missed out some option on SQL Server?


Solution

  • The long duration of the USE statement indicates the database may be set to AUTO_CLOSE ON. Overhead is incurred during database startup when it must be opened.

    The setting can be changed with:

    ALTER DATABASE [YourDatabase] SET AUTO_CLOSE OFF;