且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在C#中创建一个oracleconnection方法,以便可以重用它来获取下一个数据库

更新时间:2023-01-19 20:14:23

如果我正确理解你的问题,我不会尝试存储连接以供以后重用。相反,我会让连接池来处理缓存连接对象。请查看 Oracle Data Provider for .NET的功能 [ ^ ]



连接字符串本身的内容,您可以存储它以便快速访问,例如在配置文件中,在单个静态字符串变量等中。



例如,看看在C#中读取配置设置的四种方法 [ ^ ]
If I understand your question correctly, I wouldn't try to store the connection for later reuse. Instead I would let connection pooling to take care of caching the connection objects. Have a look at Features of Oracle Data Provider for .NET[^]

What comes to the connection string itself, you can store it for quick access for example in a configuration file, in a single, static string variable etc.

For example, have a look at Four Ways to Read Configuration Setting in C#[^]