开发者

programmatically manage db connection while using datasets

I was just thinking if there was a way to programmatically open and close connections to the database via the dataset classes we've added into the project.

I am trying to avoid one specific problem. Assume there is an Emp开发者_JAVA技巧loyeeTableAdapter. It has two methods IsValid(string EmployeeID) and HasDepartmentAccess(string EmployeeID, string DeptID). Afaik each of these methods, open a connection, does data retrieval, and then closes it.

The opening and closing of the connection is done internally. I kind of want to override this, and close the connection upon a page unload event which (I'd manually register it with the datadapter class somehow).


If you have connection pooling enabled (or disabled, because it's enabled by default) I don't recommend you to close a connection manually. Because now on every "close" connections doesn't becomes closed, they just becomes marked as closed and returns to pool and becomes to be ready to be used into a next query.

Read more at MSDN

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜