Skip to content

Commit 6e73851

Browse files
committed
Do not open connection if it is already opened. Closes #11
1 parent ffc50cf commit 6e73851

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/QueryPlanVisualizer/Helpers/DatabaseHelper.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Data;
23
using System.Data.Common;
34
using System.Data.Entity.Infrastructure;
45
using System.Data.Linq;
@@ -56,7 +57,7 @@ private static DatabaseHelper CreateEntityFrameworkDatabaseHelper<T>(IQueryable<
5657
System.Data.Objects.ObjectQuery<T>;
5758

5859
if (objectQuery != null)
59-
//EF5 uses ObjectQuery from System.Data.Objects namespace, EF6 uses System.Data.Entity.Core.Objects so it will be null
60+
//EF5 uses ObjectQuery from System.Data.Objects namespace, EF6 uses System.Data.Entity.Core.Objects so it will be null
6061
{
6162
return new EntityFramework5DatabaseHelper(objectQuery);
6263
}
@@ -84,7 +85,10 @@ public virtual string GetSqlServerQueryExecutionPlan<T>(IQueryable<T> queryable)
8485
{
8586
try
8687
{
87-
Connection.Open();
88+
if (Connection.State != ConnectionState.Open)
89+
{
90+
Connection.Open();
91+
}
8892

8993
using (var setStatisticsCommand = Connection.CreateCommand())
9094
{

0 commit comments

Comments
 (0)