当前位置:   article > 正文

.Net EntityFramework连接Mysql连接池配置_entity net

entity net

       微软的Ado.Net支持连接池,.EntityFrameworkCore.MySql同样支持连接池,并且默认也是开启连接池的,EntityFramework的使用教程请查看我的另一篇文章

EntityFramework基本使用_シ❤゛甜虾的个人博客-CSDN博客讲到EntityFramework,就先讲下数据分层VO(View Object):视图对象,用于展示层,它的作用是把某个指定页面(或组件)的所有数据封装起来。DTO(Data Transfer Object):数据传输对象,这个概念来源于J2EE的设计模式,原来的目的是为了EJB的分布式应用提供粗粒度的数据实体,以减少分布式调用的次数,从而提高分布式调用的性能和降低网络负载,但在这里,我泛指用于展示层与服务层之间的数据传输对象。DO(Domain Object):领域对象,就是从现实世界中抽https://blog.csdn.net/g313105910/article/details/119828640

.Net Entity Framework连接MySql_シ❤゛甜虾的个人博客-CSDN博客一、Nuget安装Entity Framework二、基本代码编写创建Models文件夹,然后在创建Table文件夹,在Table中创建表的实体类然后在创建DataContext类,内容如下using EdgeService.DbService.Models.Table;using Microsoft.EntityFrameworkCore;namespace EdgeService.DbService.Models{ public class DataCon...https://blog.csdn.net/g313105910/article/details/120486869

EntityFramework多线程安全和连接池问题探究_シ❤゛甜虾的个人博客-CSDN博客创建多个DataContext.AddDbContext<DataContext>(optionsBuilder => optionsBuilder.UseMySql(ConnectionString, new MySqlServerVersion(new Version(5, 7, 0)))).AddDbContext<EquipmentContext>(optionsBuilder => optionsBuilder.UseMySql(Connection..https://blog.csdn.net/g313105910/article/details/121228832

sql设置

启用连接池

string connStringUsePool = "server=.;database=master;uid=sa;pwd=123;pooling=true;connection lifetime=0;min pool size = 1;max pool size=500";

不启用连接池

string connStringUnUsePool = "server=.;database=master;uid=sa;pwd=123;pooling=false";

mysql设置

启用连接池

string connStringUsePool = "server=127.0.0.1;uid=root;pwd=xxx;database=databasetest;pooling=true;connectionlifetime=5;minpoolsize=1;maxpoolsize=500;"

不启用连接池

"server=127.0.0.1;uid=root;pwd=xxx;database=databasetest;pooling=false;"

mysql 查询连接数

show processlist

关闭线程池

开启连接池后

如果连接池不够用了,会支持抛出异常Too many connections太多的连接

  1. SelectThread:4,Exception:System.InvalidOperationException: An exception has been raised that is likely due to a transient failure. Consider enabling transient error resiliency by adding 'EnableRetryOnFailure()' to the 'UseMySql' call.
  2. ---> MySqlConnector.MySqlException (0x80004005): Too many connections
  3. at MySqlConnector.Core.ServerSession.ConnectAsync(ConnectionSettings cs, Int32 startTickCount, ILoadBalancer loadBalancer, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/ServerSession.cs:line 425
  4. at MySqlConnector.MySqlConnection.CreateSessionAsync(ConnectionPool pool, Int32 startTickCount, Nullable`1 ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlConnection.cs:line 884
  5. at MySqlConnector.MySqlConnection.OpenAsync(Nullable`1 ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlConnection.cs:line 414
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/891863
推荐阅读
相关标签
  

闽ICP备14008679号