Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
174 views
in Technique[技术] by (71.8m points)

c# - How to disable connection pool?

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/finally closing 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 file exception 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

+ "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 Pooling section


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...