diff --git a/Src/Asp.Net/SqlServerTest/Demos/A_MasterSlave.cs b/Src/Asp.Net/SqlServerTest/Demos/A_MasterSlave.cs index 65fd5ea48..112d6a776 100644 --- a/Src/Asp.Net/SqlServerTest/Demos/A_MasterSlave.cs +++ b/Src/Asp.Net/SqlServerTest/Demos/A_MasterSlave.cs @@ -13,12 +13,13 @@ namespace OrmTest.Demo public static void Init() { - var db = GetMasterSlaveInstance(); - for (int i = 0; i < 10; i++) + + for (int i = 0; i < 1000; i++) { - var list = db.Queryable().ToList(); // ConnectionString2 or ConnectionString3 + var db = GetMasterSlaveInstance(); + var list = db.Insertable(new Student() { Name="aa" }).ExecuteCommand(); // ConnectionString2 or ConnectionString3 } - db.Insertable(new Student() { Name = "masterTest" }).ExecuteCommand();// Config.ConnectionString + //db.Insertable(new Student() { Name = "masterTest" }).ExecuteCommand();// Config.ConnectionString } public static SqlSugarClient GetMasterSlaveInstance() @@ -29,8 +30,8 @@ namespace OrmTest.Demo DbType = DbType.SqlServer, IsAutoCloseConnection = true, SlaveConnectionConfigs = new List() { - new SlaveConnectionConfig() { HitRate=10, ConnectionString=Config.ConnectionString2 }, - new SlaveConnectionConfig() { HitRate=30, ConnectionString=Config.ConnectionString3 } + new SlaveConnectionConfig() { HitRate=10, ConnectionString=Config.ConnectionString2 } , + new SlaveConnectionConfig() { HitRate=10, ConnectionString=Config.ConnectionString2 } } }); db.Aop.OnLogExecuting = (sql, pars) => diff --git a/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs index 7fcb4faf9..1fa244f01 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs @@ -75,7 +75,7 @@ namespace SqlSugar { this.Connection.Close(); } - if (this.IsMasterSlaveSeparation) + if (this.IsMasterSlaveSeparation && this.SlaveConnections.HasValue()) { foreach (var slaveConnection in this.SlaveConnections) { @@ -263,7 +263,7 @@ namespace SqlSugar if (this.IsClearParameters) sqlCommand.Parameters.Clear(); ExecuteAfter(sql, parameters); - SetConnectionEnd(); + SetConnectionEnd(sql); return count; } catch (Exception ex) @@ -293,7 +293,7 @@ namespace SqlSugar if (this.IsClearParameters) sqlCommand.Parameters.Clear(); ExecuteAfter(sql, parameters); - SetConnectionEnd(); + SetConnectionEnd(sql); return sqlDataReader; } catch (Exception ex) @@ -319,7 +319,7 @@ namespace SqlSugar if (this.IsClearParameters) sqlCommand.Parameters.Clear(); ExecuteAfter(sql, parameters); - SetConnectionEnd(); + SetConnectionEnd(sql); return ds; } catch (Exception ex) @@ -347,7 +347,7 @@ namespace SqlSugar if (this.IsClearParameters) sqlCommand.Parameters.Clear(); ExecuteAfter(sql, parameters); - SetConnectionEnd(); + SetConnectionEnd(sql); return scalar; } catch (Exception ex) @@ -719,9 +719,9 @@ namespace SqlSugar return result.Count() == 0; } - private void SetConnectionEnd() + private void SetConnectionEnd(string sql) { - if (this.IsMasterSlaveSeparation) + if (this.IsMasterSlaveSeparation && IsRead(sql)) { this.Connection = this.MasterConnection; this.Context.CurrentConnectionConfig.ConnectionString = this.MasterConnection.ConnectionString; diff --git a/Src/Asp.Net/SqlSugar/Properties/AssemblyInfo.cs b/Src/Asp.Net/SqlSugar/Properties/AssemblyInfo.cs index 7a28eed1e..82dfcb9b1 100644 --- a/Src/Asp.Net/SqlSugar/Properties/AssemblyInfo.cs +++ b/Src/Asp.Net/SqlSugar/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("4.5.9.5")] -[assembly: AssemblyFileVersion("4.5.9.5")] +[assembly: AssemblyVersion("4.5.9.6")] +[assembly: AssemblyFileVersion("4.5.9.6")]