Permalink
Browse files

Fixed problem with connection opening

  • Loading branch information...
1 parent c8cd622 commit db75bbe61ff6a3719d82abb4dd5d904639a26057 @markrendle committed Nov 25, 2011
@@ -19,6 +19,6 @@
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
-[assembly: AssemblyVersion("0.11.2.1")]
-[assembly: AssemblyFileVersion("0.11.2.1")]
+[assembly: AssemblyVersion("0.11.3.1")]
+[assembly: AssemblyFileVersion("0.11.3.1")]
@@ -371,7 +371,7 @@ private int Execute(ICommandBuilder commandBuilder)
{
using (var command = commandBuilder.GetCommand(connection))
{
- connection.Open();
+ connection.OpenIfClosed();
return TryExecute(command);
}
}
@@ -449,23 +449,23 @@ public object FindRelated(string tableName, IDictionary<string, object> row, str
public IAdapterTransaction BeginTransaction()
{
var connection = CreateConnection();
- connection.Open();
+ connection.OpenIfClosed();
var transaction = connection.BeginTransaction();
return new AdoAdapterTransaction(transaction);
}
public IAdapterTransaction BeginTransaction(IsolationLevel isolationLevel)
{
var connection = CreateConnection();
- connection.Open();
+ connection.OpenIfClosed();
var transaction = connection.BeginTransaction(isolationLevel);
return new AdoAdapterTransaction(transaction);
}
public IAdapterTransaction BeginTransaction(string name)
{
var connection = CreateConnection();
- connection.Open();
+ connection.OpenIfClosed();
var sqlConnection = connection as SqlConnection;
var transaction = sqlConnection != null ? sqlConnection.BeginTransaction(name) : connection.BeginTransaction();
@@ -475,7 +475,7 @@ public IAdapterTransaction BeginTransaction(string name)
public IAdapterTransaction BeginTransaction(IsolationLevel isolationLevel, string name)
{
var connection = CreateConnection();
- connection.Open();
+ connection.OpenIfClosed();
var sqlConnection = connection as SqlConnection;
var transaction = sqlConnection != null
? sqlConnection.BeginTransaction(isolationLevel, name)
@@ -160,8 +160,7 @@ private CommandTemplate GetCommandTemplate(string tableName, SimpleExpression cr
{
try
{
- if (connection.State != ConnectionState.Open)
- connection.Open();
+ connection.OpenIfClosed();
using (var reader = command.ExecuteReader())
{
if (reader.Read())
@@ -157,8 +157,7 @@ private CommandTemplate GetCommandTemplate(string tableName, SimpleExpression cr
{
try
{
- if (connection.State != ConnectionState.Open)
- connection.Open();
+ connection.OpenIfClosed();
using (var reader = command.ExecuteReader())
{
if (reader.Read())
@@ -108,7 +108,7 @@ private void CheckInsertablePropertiesAreAvailable(Table table, IEnumerable<KeyV
{
using (var command = new CommandHelper(_adapter).CreateInsert(connection, sql, columns, values.ToArray()))
{
- connection.Open();
+ connection.OpenIfClosed();
return TryExecuteSingletonQuery(command);
}
}
@@ -131,7 +131,7 @@ private void CheckInsertablePropertiesAreAvailable(Table table, IEnumerable<KeyV
{
using (var command = new CommandHelper(_adapter).CreateInsert(connection, insertSql, columns, values.ToArray()))
{
- connection.Open();
+ connection.OpenIfClosed();
TryExecute(command);
command.CommandText = selectSql;
command.Parameters.Clear();
@@ -174,7 +174,7 @@ internal int Execute(string sql, IEnumerable<Column> columns, IEnumerable<Object
{
using (var command = new CommandHelper(_adapter).CreateInsert(connection, sql, columns, values.ToArray()))
{
- connection.Open();
+ connection.OpenIfClosed();
return TryExecute(command);
}
}
@@ -30,7 +30,7 @@ public virtual void InsertRowsWithoutFetchBack(string insertSql)
{
using (var insertCommand = new CommandHelper(Adapter).CreateInsert(connection, insertSql, _columns))
{
- connection.Open();
+ connection.OpenIfClosed();
TryPrepare(insertCommand);
insertCommand.Prepare();
foreach (var row in Data)
@@ -50,7 +50,7 @@ public virtual void InsertRowsWithoutFetchBack(string insertSql)
using (var selectCommand = connection.CreateCommand())
{
selectCommand.CommandText = selectSql;
- connection.Open();
+ connection.OpenIfClosed();
TryPrepare(insertCommand, selectCommand);
return Data.Select(row => InsertRow(row, insertCommand, selectCommand)).ToList();
}
@@ -66,7 +66,7 @@ public virtual void InsertRowsWithoutFetchBack(string insertSql)
{
using (var command = new CommandHelper(Adapter).CreateInsert(connection, insertSql, _columns))
{
- connection.Open();
+ connection.OpenIfClosed();
TryPrepare(command);
return Data.Select(row => InsertRowAndSelect(row, command)).ToList();
}
@@ -31,7 +31,7 @@ public static ConnectionScope Create(IDbTransaction transaction, Func<IDbConnect
return new ConnectionScope(transaction.Connection, false);
}
var connection = creator();
- connection.Open();
+ connection.OpenIfClosed();
return new ConnectionScope(connection, true);
}
@@ -52,8 +52,7 @@ private void ExecuteReader()
{
try
{
- if (_connection.State == ConnectionState.Closed)
- _connection.Open();
+ _connection.OpenIfClosed();
_reader = _command.ExecuteReader();
if (_reader != null)
{
@@ -53,8 +53,7 @@ private void ExecuteReader()
{
try
{
- if (_connection.State == ConnectionState.Closed)
- _connection.Open();
+ _connection.OpenIfClosed();
_reader = _command.ExecuteReader();
_index = _index ?? _reader.CreateDictionaryIndex();
}
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Simple.Data.Ado
+{
+ using System.Data;
+
+ static class DbConnectionEx
+ {
+ public static void OpenIfClosed(this IDbConnection connection)
+ {
+ if (connection.State == ConnectionState.Closed)
+ {
+ connection.Open();
+ }
+ }
+ }
+}
@@ -99,7 +99,7 @@ public virtual IDbCommand CreateCommand()
/// <filterpriority>2</filterpriority>
public virtual void Open()
{
- _delegatedConnection.Open();
+ _delegatedConnection.OpenIfClosed();
}
/// <summary>
@@ -19,8 +19,7 @@ class ObservableQueryRunner : IObservableQueryRunner
{
try
{
- if (connection.State == ConnectionState.Closed)
- connection.Open();
+ connection.OpenIfClosed();
}
catch (DbException ex)
{
@@ -71,7 +71,7 @@ private static void RetrieveOutputParameterValues(Procedure procedure, IDbComman
public IEnumerable<ResultSet> ExecuteReader(IDbCommand command)
{
command.WriteTrace();
- command.Connection.Open();
+ command.Connection.OpenIfClosed();
using (var reader = command.ExecuteReader())
{
// Reader isn't always returned - added check to stop NullReferenceException
@@ -90,7 +90,7 @@ private static IEnumerable<ResultSet> ExecuteNonQuery(IDbCommand command)
{
command.WriteTrace();
Trace.TraceInformation("ExecuteNonQuery", "Simple.Data.SqlTest");
- command.Connection.Open();
+ command.Connection.OpenIfClosed();
command.ExecuteNonQuery();
return Enumerable.Empty<ResultSet>();
}
@@ -69,6 +69,7 @@
<Compile Include="DataReaderMultipleEnumerator.cs" />
<Compile Include="DataRecordExtensions.cs" />
<Compile Include="DbCommandExtensions.cs" />
+ <Compile Include="DbConnectionEx.cs" />
<Compile Include="DbConnectionExtensions.cs" />
<Compile Include="DelegatingConnectionBase1.cs" />
<Compile Include="DeleteHelper.cs" />
@@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Simple.Data.Ado</id>
- <version>0.11.2.1</version>
+ <version>0.11.3.1</version>
<authors>Mark Rendle</authors>
<owners>Mark Rendle</owners>
<description>ADO Adapter for the Simple.Data data access library.</description>
@@ -12,7 +12,7 @@
<tags>sqlserver database data ado .net40</tags>
<language>en-us</language>
<dependencies>
- <dependency id="Simple.Data.Core" version="0.11.2.1" />
+ <dependency id="Simple.Data.Core" version="0.11.3.1" />
</dependencies>
</metadata>
</package>
@@ -2,7 +2,7 @@
<package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>Simple.Data.Mocking</id>
- <version>0.11.2.1</version>
+ <version>0.11.3.1</version>
<authors>Mark Rendle</authors>
<owners>Mark Rendle</owners>
<description>XML-based Mocking adapter for the Simple.Data data access library.</description>
@@ -12,7 +12,7 @@
<tags>database data .net40</tags>
<language>en-us</language>
<dependencies>
- <dependency id="Simple.Data.Ado" version="0.11.2.1" />
+ <dependency id="Simple.Data.Ado" version="0.11.3.1" />
</dependencies>
</metadata>
</package>
@@ -2,7 +2,7 @@
<package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>Simple.Data.SqlCompact40</id>
- <version>0.11.2.1</version>
+ <version>0.11.3.1</version>
<authors>Mark Rendle</authors>
<owners>Mark Rendle</owners>
<description>SQL Server Compact 4.0 ADO provider for the Simple.Data data access library.</description>
@@ -12,7 +12,7 @@
<tags>sqlserver compact sqlce database data ado .net40</tags>
<language>en-us</language>
<dependencies>
- <dependency id="Simple.Data.Ado" version="0.11.2.1" />
+ <dependency id="Simple.Data.Ado" version="0.11.3.1" />
</dependencies>
</metadata>
</package>
@@ -2,7 +2,7 @@
<package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>Simple.Data.SqlServer</id>
- <version>0.11.2.1</version>
+ <version>0.11.3.1</version>
<authors>Mark Rendle</authors>
<owners>Mark Rendle</owners>
<description>SQL Server ADO provider for the Simple.Data data access library.</description>
@@ -12,7 +12,7 @@
<tags>sqlserver database data ado .net40</tags>
<language>en-us</language>
<dependencies>
- <dependency id="Simple.Data.Ado" version="0.11.2.1" />
+ <dependency id="Simple.Data.Ado" version="0.11.3.1" />
</dependencies>
</metadata>
</package>
@@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Simple.Data.Core</id>
- <version>0.11.2.1</version>
+ <version>0.11.3.1</version>
<authors>Mark Rendle</authors>
<owners>Mark Rendle</owners>
<licenseUrl>http://www.opensource.org/licenses/mit-license.php</licenseUrl>

0 comments on commit db75bbe

Please sign in to comment.