code first 连接池的问题

ananmxw 2014-11-06 06:06:28
使用codefirst存储数据的时候,

using(var context=new MMSConnection())
{
}

这是每次生成一个新的连接,还是从已有的链接池里取出一个连接?,或者说怎样使用连接池啊?
敬请大侠帮忙一下!!!
...全文
436 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
ananmxw 2014-11-10
  • 打赏
  • 举报
回复
引用 11 楼 github_22161131 的回复:
EF和连接池没关系,连接池由底层的ado.net data provider提供,sql server的provider默认就是启用连接池的。你的连接字符串里写了“Max Pool Size=30; Min Pool Size=5”会调整连接池大小上下限,默认是max=100,min=0
也就是说,我写的连接字符串中,对线程池的最大最小设置是没有作用的,var context=new MMSConnection()是生成一个新的链接,而不是从线程池里分配一个,是这样理解吗?
winnowc 2014-11-10
  • 打赏
  • 举报
回复
引用 12 楼 ananmxw 的回复:
[quote=引用 11 楼 github_22161131 的回复:] EF和连接池没关系,连接池由底层的ado.net data provider提供,sql server的provider默认就是启用连接池的。你的连接字符串里写了“Max Pool Size=30; Min Pool Size=5”会调整连接池大小上下限,默认是max=100,min=0
也就是说,我写的连接字符串中,对线程池的最大最小设置是没有作用的,var context=new MMSConnection()是生成一个新的链接,而不是从线程池里分配一个,是这样理解吗?[/quote] (上面的“线程池”应该还是说连接池吧) 不是,我的意思是连接池是由ado.net provider管理,在连接字符串里面的设置是有作用的。EF在打开连接的时候也是依赖底层的provider,它自己不管理连接池。也就是说只要不关闭连接池,EF都是从连接池获取的连接。
winnowc 2014-11-07
  • 打赏
  • 举报
回复
EF和连接池没关系,连接池由底层的ado.net data provider提供,sql server的provider默认就是启用连接池的。你的连接字符串里写了“Max Pool Size=30; Min Pool Size=5”会调整连接池大小上下限,默认是max=100,min=0
ananmxw 2014-11-07
  • 打赏
  • 举报
回复
顶一下,顶一下
ananmxw 2014-11-07
  • 打赏
  • 举报
回复
引用 1 楼 sunny906 的回复:
在数据库的连接串里设置连接池大小:Server=xx; Integrated Security=SSPI; Database=xx;MaxPoolSize=xx; MinPoolSize=xx
这样设置以后,使用的时候是怎样使用的啊,var context=new MMSConnection(),这里是生成了一个新的连接,还是从连接池分配了一个连接?
ananmxw 2014-11-07
  • 打赏
  • 举报
回复
引用 9 楼 xdashewan 的回复:
[quote=引用 8 楼 ananmxw 的回复:] 如果我想用连接池,应该怎样做呢?
貌似是根据你的链接字符串来判断的,如果你字符串里有Pooling就默认为池操作 参考http://www.cnblogs.com/youring2/archive/2011/06/18/2084442.html[/quote] 在ado和ODBC中有明确说明,Open是分配一个连接池,但是在这里没有找到相关说明,所以不确定,故发此贴
xdashewan 2014-11-07
  • 打赏
  • 举报
回复
引用 8 楼 ananmxw 的回复:
如果我想用连接池,应该怎样做呢?
貌似是根据你的链接字符串来判断的,如果你字符串里有Pooling就默认为池操作 参考http://www.cnblogs.com/youring2/archive/2011/06/18/2084442.html
ananmxw 2014-11-07
  • 打赏
  • 举报
回复
引用 7 楼 xdashewan 的回复:
每次创建一个新链接,但会在最后自动销毁该链接
如果我想用连接池,应该怎样做呢?
xdashewan 2014-11-07
  • 打赏
  • 举报
回复
每次创建一个新链接,但会在最后自动销毁该链接
ananmxw 2014-11-07
  • 打赏
  • 举报
回复
引用 5 楼 xdashewan 的回复:
你得去看MMSConnection里面怎么写的
public class MMSConnection : DbContext
    {
        //
        // Summary:
        //     Creates a Database instance for this context that allows for creation/deletion/existence
        //     checks for the underlying database.

        public MMSConnection()
            : base("name=LocalConnection")
        {
        }

        //报警
        public DbSet<DB_Alarm> Alarms { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            //注意:类对应的数据库表名必须全为小写字母,因为MySQL数据库table和schema的命名不支持大写。

            modelBuilder.Entity<DB_Alarm>().ToTable("alarm");
        }
    }
以下是配置文件中的链接语句
    <add name="LocalConnection" connectionString="Data Source=localhost;port=3306;Initial Catalog=MMSDB;Max Pool Size=30; Min Pool Size=5;user id=root;password=***" providerName="MySql.Data.MySqlClient" />
xdashewan 2014-11-07
  • 打赏
  • 举报
回复
你得去看MMSConnection里面怎么写的
ananmxw 2014-11-07
  • 打赏
  • 举报
回复
没人知道?
sunny906 2014-11-06
  • 打赏
  • 举报
回复
在数据库的连接串里设置连接池大小:Server=xx; Integrated Security=SSPI; Database=xx;MaxPoolSize=xx; MinPoolSize=xx

17,747

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧