Last post Dec 29, 2005 11:37 AM by latticesoft
Dec 21, 2005 04:14 AM|Minaki|LINK
I've been using Microsoft.ApplicationBlocks.Data in my projects recently and until now I havn't had any problems. However recently I have found that I am getting timeout errors due to there not being any SQL Connections left in the pool. I know this is most
likely due to a connection not being closed properly somewhere, but I thought Microsoft.ApplicationBlocks.Data encapsulated all the stuff to do with connections?
The only thing I can think of is when using ExecuteReader because the SqlDataReader is a conencted object and requires the conenction to be open while it is being used. The question is, how to I explicitly close the connection after using an SqlDataReader
if the connection object is maintained inside the function I'm calling? Or do I just close the SqlDataReader? What about when using an SqlDataReader as the data source for a control?
Dec 21, 2005 10:37 AM|latticesoft|LINK
ExecuteDataSet internally use ExecuteReader, if something went wrong during process, it is still possible keep connection open.
>>how to I explicitly close the connection after using an SqlDataReader if the connection object is >>maintained inside the function I'm calling?
You can pass CommandBehavior.CloseConnection to the ExecuteReader method to ensure that the associated connection is closed when the
DataReader is closed.
>>What about when using an SqlDataReader as the data source for a control?
DataBind DataReader to your control is not good idea use custom object instead if you follow three tier architectire:
Your DAL fetch data from database return DataReader, then your BL build strong type custom object return to UI and databind to server control.
Dec 26, 2005 05:50 PM|Minaki|LINK
Cool I've solved the problem with the connections now - there were a couple of places where I'd forgotton to close the SqlDataReader.
When I create this custom object, do I...
- Create a class that implements IList
- Create a class derived from ArrayList, or
- Create an ArrayList and fill it with my custom objects?
Dec 27, 2005 12:54 AM|latticesoft|LINK
The simplest way is to create an ArrayList and fill it with your custom objects.
Dec 29, 2005 04:32 AM|Minaki|LINK
So now I have an ArrayList filled with my object, and it binds OK to a drop down list. What do I use for the DataKeyField and DataValueField members of the DropDown list? Or how do I refer to the selected item?
Dec 29, 2005 11:37 AM|latticesoft|LINK
You can map Dropdwon list's DataValueField to your custom object public property's name, and refer it using SelectedItem.Value.