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

Commit 41fbd8a

Browse files
committed
Set isOpen=false when closing a Factory OrmLiteConnection
1 parent 2944581 commit 41fbd8a

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

src/ServiceStack.OrmLite/OrmLiteConnection.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public IDbTransaction BeginTransaction(IsolationLevel isolationLevel)
6262

6363
public void Close()
6464
{
65+
isOpen = false;
6566
DbConnection.Close();
6667
}
6768

@@ -83,7 +84,8 @@ public IDbCommand CreateCommand()
8384

8485
public void Open()
8586
{
86-
if (isOpen) return;
87+
if (isOpen)
88+
return;
8789

8890
DbConnection.Open();
8991
//so the internal connection is wrapped for example by miniprofiler

tests/ServiceStack.OrmLite.Tests/OrmLiteConnectionFactoryTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Data;
23
using Northwind.Common.DataModel;
34
using NUnit.Framework;
45
using ServiceStack.Text;
@@ -154,5 +155,21 @@ public void Can_open_multiple_nested_connections_in_any_order()
154155
Assert.AreEqual(new[] { 3, 4, 5, 6, 1, 2 }, ids);
155156
}
156157

158+
159+
[Test]
160+
public void Can_open_after_close_connection()
161+
{
162+
OrmLiteConfig.DialectProvider = SqliteDialect.Provider;
163+
var factory = new OrmLiteConnectionFactory(":memory:");
164+
using (var db = factory.OpenDbConnection())
165+
{
166+
Assert.That(db.State, Is.EqualTo(ConnectionState.Open));
167+
db.Close();
168+
Assert.That(db.State, Is.EqualTo(ConnectionState.Closed));
169+
db.Open();
170+
Assert.That(db.State, Is.EqualTo(ConnectionState.Open));
171+
}
172+
}
173+
157174
}
158175
}

tests/ServiceStack.OrmLite.Tests/SqliteOrmLiteConnectionTests.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Data;
23
using System.IO;
34
using NUnit.Framework;
45
using ServiceStack.Common.Tests.Models;
@@ -68,5 +69,17 @@ public void Can_open_two_ReadOnlyConnections_to_same_database()
6869
}
6970
}
7071

71-
}
72+
[Test]
73+
public void Can_open_after_close_connection()
74+
{
75+
using (var db = OpenDbConnection())
76+
{
77+
Assert.That(db.State, Is.EqualTo(ConnectionState.Open));
78+
db.Close();
79+
Assert.That(db.State, Is.EqualTo(ConnectionState.Closed));
80+
db.Open();
81+
Assert.That(db.State, Is.EqualTo(ConnectionState.Open));
82+
}
83+
}
84+
}
7285
}

0 commit comments

Comments
 (0)