Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 7912fdd

Browse files
committed
Change to OrmLiteConnection open state to use ADO.NET IDbConection.State
1 parent 41fbd8a commit 7912fdd

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/ServiceStack.OrmLite/OrmLiteConnection.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public class OrmLiteConnection
1313
public readonly OrmLiteConnectionFactory Factory;
1414
public IDbTransaction Transaction { get; set; }
1515
private IDbConnection dbConnection;
16-
private bool isOpen;
1716

1817
public OrmLiteConnection(OrmLiteConnectionFactory factory)
1918
{
@@ -39,7 +38,6 @@ public void Dispose()
3938

4039
DbConnection.Dispose();
4140
dbConnection = null;
42-
isOpen = false;
4341
}
4442

4543
public IDbTransaction BeginTransaction()
@@ -62,7 +60,6 @@ public IDbTransaction BeginTransaction(IsolationLevel isolationLevel)
6260

6361
public void Close()
6462
{
65-
isOpen = false;
6663
DbConnection.Close();
6764
}
6865

@@ -84,13 +81,15 @@ public IDbCommand CreateCommand()
8481

8582
public void Open()
8683
{
87-
if (isOpen)
88-
return;
84+
if (DbConnection.State == ConnectionState.Broken)
85+
DbConnection.Close();
8986

90-
DbConnection.Open();
91-
//so the internal connection is wrapped for example by miniprofiler
92-
if (Factory.ConnectionFilter != null) { dbConnection = Factory.ConnectionFilter(dbConnection); }
93-
isOpen = true;
87+
if (DbConnection.State == ConnectionState.Closed)
88+
{
89+
DbConnection.Open();
90+
//so the internal connection is wrapped for example by miniprofiler
91+
if (Factory.ConnectionFilter != null) { dbConnection = Factory.ConnectionFilter(dbConnection); }
92+
}
9493
}
9594

9695
public string ConnectionString

0 commit comments

Comments
 (0)