From 2cf85ba8887a20172440c4db64653cd986380fbd Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Tue, 12 Sep 2017 18:48:02 +0800 Subject: [PATCH] - --- .../SqlSugar/Abstract/AdoProvider/AdoProvider.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs index d03f76b23..3853a15ef 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs @@ -235,7 +235,7 @@ namespace SqlSugar if (this.IsClearParameters) sqlCommand.Parameters.Clear(); ExecuteAfter(sql, parameters); - if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection && this.Transaction == null) this.Close(); + if (this.IsClose()) this.Close(); return count; } public virtual IDataReader GetDataReader(string sql, params SugarParameter[] parameters) @@ -245,8 +245,7 @@ namespace SqlSugar ExecuteProcessingSQL(ref sql, parameters); ExecuteBefore(sql, parameters); IDbCommand sqlCommand = GetCommand(sql, parameters); - var isAutoClose = this.Context.CurrentConnectionConfig.IsAutoCloseConnection && this.Transaction == null; - IDataReader sqlDataReader = sqlCommand.ExecuteReader(isAutoClose ? CommandBehavior.CloseConnection : CommandBehavior.Default); + IDataReader sqlDataReader = sqlCommand.ExecuteReader(this.IsClose() ? CommandBehavior.CloseConnection : CommandBehavior.Default); if (isSp) DataReaderParameters = sqlCommand.Parameters; if (this.IsClearParameters) @@ -267,7 +266,7 @@ namespace SqlSugar if (this.IsClearParameters) sqlCommand.Parameters.Clear(); ExecuteAfter(sql, parameters); - if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection && this.Transaction == null) this.Close(); + if (this.IsClose()) this.Close(); return ds; } public virtual object GetScalar(string sql, params SugarParameter[] parameters) @@ -281,7 +280,7 @@ namespace SqlSugar if (this.IsClearParameters) sqlCommand.Parameters.Clear(); ExecuteAfter(sql, parameters); - if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection && this.Transaction == null) this.Close(); + if (this.IsClose()) this.Close(); return scalar; } #endregion @@ -603,6 +602,10 @@ namespace SqlSugar if (parameters == null) return null; return base.GetParameters(parameters, propertyInfo, this.SqlParameterKeyWord); } + private bool IsClose() + { + return this.Context.CurrentConnectionConfig.IsAutoCloseConnection && this.Transaction == null; + } #endregion } }