如何禁用连接池? [英] 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();
}
确保我可以正确处理异常,并在try/catch/最终中关闭并处置连接对象.但是,通常我会收到正在举行oracle会话的oracle服务消息.此外,如果我只是让我的应用程序处于打开状态,并且第二天尝试进行操作,则我第一次遇到ora-12537 network session end of file
异常,那么第二次尝试正在进行.经过一番阅读后,看来我必须禁用连接池.如果这是正确的解决方法,那么如何禁用池?如果没有,那么还有什么其他事情可能是错误的?
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?
推荐答案
您可以在连接字符串中添加Pooling=False
,但这意味着每次都会创建一个新的连接.
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
这篇关于如何禁用连接池?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!