Skip to content

Commit 2a89718

Browse files
committed
scoped the connection open and close at the wrong level in the code
1 parent 062e2db commit 2a89718

File tree

6 files changed

+29
-8
lines changed

6 files changed

+29
-8
lines changed

SubSonic.Extensions.Test/MockDbClient/MockDBErrors.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SubSonic.Extensions.Test/MockDbClient/MockDBErrors.resx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,11 @@
117117
<resheader name="writer">
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120+
<data name="ConnectionStateAlreadyOpen" xml:space="preserve">
121+
<value>Connection State Already Open.</value>
122+
</data>
120123
<data name="ConnectionStateNotOpen" xml:space="preserve">
121-
<value>Connection State Not Open</value>
124+
<value>Connection State Not Open.</value>
122125
</data>
123126
<data name="MissingDbParameter" xml:space="preserve">
124127
<value>Missing expected db parameter.</value>

SubSonic.Extensions.Test/MockDbClient/MockDbConnection.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ public override string Database
5555

5656
public override void Open()
5757
{
58+
if (state == ConnectionState.Open)
59+
{
60+
throw Error.InvalidOperation(MockDBErrors.ConnectionStateAlreadyOpen);
61+
}
62+
5863
state = ConnectionState.Open;
5964
}
6065

SubSonic/Infrastructure/Builders/DbSqlQueryBuilder/DbSqlQueryBuilderQueryProvider.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ public object Execute(Expression expression)
190190

191191
bool isEntityModel = DbContext.DbModel.IsEntityModelRegistered(elementType);
192192

193+
Scope.Connection.Open();
194+
193195
using (DbDataReader reader = Scope.Database.ExecuteReader(dbQuery))
194196
{
195197
if (reader.HasRows)
@@ -218,6 +220,8 @@ public object Execute(Expression expression)
218220
finally
219221
{
220222
dbQuery.CleanUpParameters();
223+
224+
Scope.Connection.Close();
221225
}
222226
}
223227
}

SubSonic/Infrastructure/Database/DbDatabase.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,13 @@ public DbDataReader ExecuteReader(IDbQuery queryObject)
264264

265265
try
266266
{
267-
cmd.Connection.Open();
268-
269267
return cmd.ExecuteReader(queryObject.Behavior);
270268
}
271-
finally
272-
{
273-
cmd.Connection.Close();
269+
catch(DataException ex)
270+
{
271+
logger.LogCritical(ex, ex.Message);
272+
273+
throw;
274274
}
275275
}
276276
}

SubSonic/SubSonic.Core.DataAccessLayer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<IncludeSymbols>true</IncludeSymbols>
1010
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
1111
<PackageTags>DAL;SqlServer;C#;.NetFramework;.NetCore;</PackageTags>
12-
<Version>4.1.0-alpha.3</Version>
12+
<Version>4.1.0-alpha.4</Version>
1313
<PackageId>SubSonic.Core.DAL</PackageId>
1414
<Company>SubSonic-Core</Company>
1515
<PackageProjectUrl>https://github.com/SubSonic-Core/SubSonic/wiki</PackageProjectUrl>

0 commit comments

Comments
 (0)