Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server Profiler showing EF queries against master database?

What am I missing here? The queries I see in SQL Server Profiler are all targeted against the master database, which makes it difficult to filter by database name ... which event or events should I be watching so I can filter by database name.

The bigger question, what exactly is going on here?

like image 593
mattruma Avatar asked Dec 03 '22 09:12

mattruma


2 Answers

You should remove this 'MultipleActiveResultSets=True' from your EntityFramework connection

string

after that, you can see the target database name show in the Profiler , instead of master.

In my option, maybe ADO.NET team want to make use the MultipleActiveResultSets feature to get

data from DB, so they have to access master.

MultipleActiveResultSets is about raise one query and don't return all its result (like in foreach statement in LINQ) , and in the same time ,raise another query to get another data in the same session.

By default, this behavior is not allowed by DB. SO.....

like image 139
Rui Avatar answered Dec 24 '22 13:12

Rui


I was able to get around this issue, including leaving MARS active by adding an application name to my connection string:

Data Source=database_server;Initial Catalog=MyDatabase;Trusted Connection=true;MultipleActiveResultSets=True;Application Name=MyDatabase;

Then you can filter on application name.

like image 35
scottm Avatar answered Dec 24 '22 15:12

scottm