Skip to content

Commit

Permalink
Fix for issue 2590. Revert changeset 6f4a591. I.e. remove interceptor…
Browse files Browse the repository at this point in the history
… that turned on DBCC 9481 flag. The flag could only be used by admin users and our queries have changed so the flag should no longer be necessary.
  • Loading branch information
lajones committed Dec 18, 2014
1 parent 4187b1c commit 5856e08
Showing 1 changed file with 0 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ namespace Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.Schema
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.Common.CommandTrees;
using System.Data.Entity.Core.EntityClient;
using System.Data.Entity.Infrastructure.Interception;
using System.Data.Entity.Utilities;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
Expand All @@ -22,8 +18,6 @@ internal class EntityStoreSchemaGeneratorDatabaseSchemaLoader
private readonly EntityConnection _connection;
private readonly Version _storeSchemaModelVersion;

private const string ProviderNameSqlclient = "System.Data.SqlClient";

public EntityStoreSchemaGeneratorDatabaseSchemaLoader(EntityConnection entityConnection, Version storeSchemaModelVersion)
{
Debug.Assert(entityConnection != null, "entityConnection != null");
Expand All @@ -34,31 +28,15 @@ public EntityStoreSchemaGeneratorDatabaseSchemaLoader(EntityConnection entityCon
_storeSchemaModelVersion = storeSchemaModelVersion;
}

internal class QueryTraceOn9481Interceptor : DbCommandInterceptor
{
[SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities",
Justification = "The only SQL passed to this method consists of pre-defined queries over which the user has no control")]
public override void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
{
// Enables the 9481 trace flag to deal with Sql Server 2014 performance regression
// See Codeplex #2445
command.CommandText = command.CommandText + " OPTION (QUERYTRACEON 9481)";
base.ReaderExecuting(command, interceptionContext);
}
}

// virtual for testing
public virtual StoreSchemaDetails LoadStoreSchemaDetails(IList<EntityStoreSchemaFilterEntry> filters)
{
Debug.Assert(filters != null, "filters != null");

QueryTraceOn9481Interceptor interceptor = null;
try
{
_connection.Open();

interceptor = CreateAndRegisterTrace9481InterceptorIfSqlServer();

return new StoreSchemaDetails(
LoadTableDetails(filters),
LoadViewDetails(filters),
Expand All @@ -70,30 +48,10 @@ public virtual StoreSchemaDetails LoadStoreSchemaDetails(IList<EntityStoreSchema
}
finally
{
if (interceptor != null)
{
DbInterception.Remove(interceptor);
}
_connection.Close();
}
}

private QueryTraceOn9481Interceptor CreateAndRegisterTrace9481InterceptorIfSqlServer()
{
QueryTraceOn9481Interceptor interceptor = null;
var storeProviderFactory = _connection.StoreProviderFactory;
if (storeProviderFactory != null)
{
var providerInvariantName = storeProviderFactory.GetProviderInvariantName();
if (string.CompareOrdinal(providerInvariantName, ProviderNameSqlclient) == 0)
{
interceptor = new QueryTraceOn9481Interceptor();
DbInterception.Add(interceptor);
}
}
return interceptor;
}

// internal virtual for testing
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
internal virtual IEnumerable<TableDetailsRow> LoadTableDetails(IEnumerable<EntityStoreSchemaFilterEntry> filters)
Expand Down

0 comments on commit 5856e08

Please sign in to comment.