使用.net MySql连接器无法关闭MySql连接 [英] MySql Connection not closing using .net MySql Connector

查看:142
本文介绍了使用.net MySql连接器无法关闭MySql连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MySql Connection将进入睡眠模式,而不是在mysql中关闭.我正在使用MySql.Data 6.5.4版本与mysql通信.我不确定下面的代码在做什么错.

MySql Connection is going to sleep mode instead of close in mysql. I am using MySql.Data 6.5.4 version to communicate with mysql. I am not sure what am I doing wrong in below code.

   try
        {
            using (var conn = new MySqlConnection(strConnection))
            {
                conn.Open();

                using (var cmd = new MySqlCommand(strSQLStatement, conn))
                {
                    var adapter = new MySqlDataAdapter(cmd);
                    adapter.Fill(ds);
                }
            }
        }
        catch (Exception ex)
        {
            ErrorLogger.WriteError(string.Format("Failed query {0} with stack trace {1} ", strSQLStatement, ex), "GetData");
        }

推荐答案

正在将您的连接添加到连接池中,此功能默认情况下处于启用状态,因此无论何时关闭连接,都会将其添加到连接池中.您可以通过连接字符串参数Pooling=false或静态方法MySqlConnection.ClearPool(connection)MySqlConnection.ClearAllPools() ...

Your connection is being added to the connection pool, this feature is on by default so whenever a connection is closed it is added to a connection pool. You can either solve this problem by connection string parameter Pooling=false or the static methods MySqlConnection.ClearPool(connection) and MySqlConnection.ClearAllPools()...

连接器/网络支持连接池,以提高数据库密集型应用程序的性能和可伸缩性.默认情况下启用.您可以使用连接字符串选项池化",连接重置",连接生存时间",缓存服务器属性",最大池大小"和最小池大小"来关闭它或调整其性能特征.

The Connector/Net supports connection pooling for better performance and scalability with database-intensive applications. This is enabled by default. You can turn it off or adjust its performance characteristics using the connection string options Pooling, Connection Reset, Connection Lifetime, Cache Server Properties, Max Pool Size and Min Pool Size.

当客户端处理MySqlConnection时,连接池通过保持与服务器的本机连接处于活动状态而起作用.随后,如果打开了一个新的MySqlConnection对象,则将从连接池中创建它,而不是创建一个新的本机连接.这样可以提高性能.

Connection pooling works by keeping the native connection to the server live when the client disposes of a MySqlConnection. Subsequently, if a new MySqlConnection object is opened, it will be created from the connection pool, rather than creating a new native connection. This improves performance.

这篇关于使用.net MySql连接器无法关闭MySql连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆