ASP.NET - 在数据集中动态创建数据库连接
我目前正在使用数据集作为我的数据访问层。我当前将连接字符串存储在 web.config 文件中。我需要能够在处理任何查询之前更改与另一个数据库的连接。是否有触发的事件或可以修改的基类拦截从 web.config 文件检索连接字符串的过程?有没有办法使用相同的代码库处理多个数据库连接并利用连接池?我知道最好的方法是摆脱数据集并使用自定义数据对象。有什么想法吗?
I am currently using datasets for my data access layer. I currently store the connection string in the web.config file. I need the ability to change the connection to another database before any queries are processed. Is there an event that is triggered or a base class that can be modified that intercepts the process of retrieving the connection string from the web.config file? Is there any way to handle multiple database connections using the same code base and also take advantage of the connection pooling? I understand the best method is to get rid of datasets and use custom data objects. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
连接池基于连接字符串,因此为您创建的每个 SqlConnection 动态更改连接池将达不到其目的。
Connection Pooling is based on the connection string so changing it dynamically for each
SqlConnection
you are creating will defeat its purpose.如果您使用数据适配器,您可以只说:
池化是自动的(如果使用相同的连接字符串)。
If you use the dataadapters you can just say :
Pooling is automatic (if same connectionstring is used).