oracle 如何禁用连接池?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32841150/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:01:46  来源:igfitidea点击:

How to disable connection pool?

c#oracleodp.net

提问by Pablo

Connection string that my app is using to connect to DB is the following:

我的应用程序用于连接到数据库的连接字符串如下:

    private const string oradb = "Data Source=(DESCRIPTION=(ADDRESS_LIST="
                    + "(ADDRESS=(PROTOCOL=TCP)(HOST=host.name)(PORT=1521)))"
                    + "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=service.name)));"
                    + "User Id=myusername;Password=mypass;";

In all DB access points of my app I am using the following pattern:

在我的应用程序的所有数据库访问点中,我使用以下模式:

        OracleConnection conn = new OracleConnection(oradb);

        try
        {
            Console.WriteLine("Opening DB Connection...");
            conn.Open();

            string queryString = string.Format(@"SELECT ...");

            using (OracleCommand command = new OracleCommand(queryString, conn))
            {
                using (OracleDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                     ...
                    }
                }
            }
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception occured during DB access: {0}", e.Message);
            dbr.Error = e.Message;
        }
        finally
        {
            Console.WriteLine("Closing DB connection");
            conn.Close();
            conn.Dispose();
        }

For sure I am properly handling exceptions and in try/catch/finallyclosing AND disposing connection object. However, often I am receiving oracle service message that I am holding oracle sessions. Moreover, if I just leave my app open and next day try to make operation, I am getting ora-12537 network session end of fileexception first time, then second attempt is going through. After some reading it looks like I have to disable connection pool. If this is the right way to solve, how to disable pool? If not, then what other thing can be wrong?

可以肯定的是,我正在正确处理异常并在 try/catch/ 中最终关闭和处理连接对象。但是,我经常收到 oracle 服务消息,我正在举行 oracle 会话。此外,如果我只是让我的应用程序打开并在第二天尝试进行操作,我ora-12537 network session end of file第一次遇到异常,然后第二次尝试正在进行。经过一番阅读,看来我必须禁用连接池。如果这是正确的解决方法,如何禁用池?如果没有,那么还有什么其他事情可能是错的?

回答by christiandev

You could add Pooling=Falsein the connection string, but this means a new connection is created each time.

您可以添加Pooling=False连接字符串,但这意味着每次都会创建一个新连接。

+ "User Id=myusername;Password=mypass;Pooling=False;";

Take a look at this article, it might help with your issue. Also, take a look at this website page, specifically the Using Connection Poolingsection

看看这篇文章,它可能会帮助您解决问题。另外,看看这个网站页面,特别是使用连接池部分