DAAB(Data Access Application Block) 2.0 connection problem.

G

Guest

I created a function to use DAAB return a datareader. The connection must
keep opening when I consume the datareader.

1. I tested the function, it works. Even I use the datareader after 10
seconds.
2. DAAB document said that it manages the connection.
3. From .NET programming point view, no guaranty for the connection opens.

Any suggestion?
Thanks.


------------------------------------------

Public Function GetDataReader(ByVal connectionStr As String, ByVal
sqlCommand As String) As IDataReader
Dim db As SqlDatabase = New SqlDatabase(connectionStr)
Dim dbCommand As DbCommand = db.GetSqlStringCommand(sqlCommand)
Return db.ExecuteReader(dbCommand)
End Function
 
G

Guest

Mike,
First of all you are posting VB.NET sample code in the C# language
newsgroup. That's not a big deal, but you're really in the wrong group.

The v2 DAAB ("SqlHelper") class manages opening and closing connections but
not for DataReaders.

When you return a DataReader from a method, you've got an open connection.
If you "do your stuff" and you have set CommandBehavior.CloseConnection on
the Command object, the connection will close when you close the Datareader.

However, this is a practice that I"ve seen droves of developers get
themselves in trouble with because of not understanding that a datareader
holds the connection open, and best - practices coding technique dictates
that you should not do this.

In fact, I recommend that developers avoid datareaders completely - for just
this reason.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top