can enterprise library data access use Sqlconnection

Topics: Data Access Application Block
Mar 14, 2012 at 9:51 AM

if not using EnterpriseLibraryContainer.Current.GetInstance<Database>("ChequeConnectionString") or DatabaseFactory.CreateDatabase()
can we pass a Sqlconnection to enterprise library data access to use?

as would like to make sqlconnection continue open by setting connection timeout = 0, only close connection at logout or close page

Mar 14, 2012 at 6:22 PM

There are no Database constructors that take an actual connection.  The design philosophy of the block is to manage the connections for you.  

You can get a connection using the CreateConnection() method or retrieve a connection string, modify it and create a new Database object.  However, for most of the methods the block will manage the connections internally anyway so I'm not sure that will buy anything.

Perhaps the best approach would be to retrieve the connection string from the existing Database object, modify it (you can use one of the DbConnectionStringBuilder classes to do this quite easily) and from there use a straight ADO.NET approach which would allow you to manage all aspects of connection lifetime.  

Randy Levy
Enterprise Library support engineer