Connecting Tech Pros Worldwide Help | Site Map

How to write CommandBehaviour.CloseConnection() in VS2008?

Newbie
 
Join Date: Apr 2009
Posts: 21
#1: Sep 9 '09
iaM NOT ABLE TO WRITE CommandBehavior.CloseConnection() in VS2008?
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,148
#2: Sep 9 '09

re: How to write CommandBehaviour.CloseConnection() in VS2008?


I'll take your word that you cannot.
If you just want to close your database connection, consider calling the Close() function on the connection object?
Newbie
 
Join Date: Apr 2009
Posts: 21
#3: Sep 10 '09

re: How to write CommandBehaviour.CloseConnection() in VS2008?


CommandBehaviour is a property of something.but i don't remember?
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,148
#4: Sep 10 '09

re: How to write CommandBehaviour.CloseConnection() in VS2008?


Quote:

Originally Posted by sarangrao View Post

CommandBehaviour is a property of something.but i don't remember?

If you don't remember what its a property of, maybe its still there, but you haven't found the right object yet?
codegecko's Avatar
Moderator
 
Join Date: May 2007
Location: United Kingdom
Posts: 395
#5: Sep 10 '09

re: How to write CommandBehaviour.CloseConnection() in VS2008?


It's a property of a DataReader according to MSDN.

Try this:
Expand|Select|Wrap|Line Numbers
  1. DbDataReader dr = yourCommand.ExecuteReader();
  2. dr.CommandBehaviour = CommandBehaviour.CloseConnection;
  3.  
  4. while (dr.Read()) {
  5.     //Iteration logic here
  6. }
  7.  
Let us know if this works.

codegecko
Newbie
 
Join Date: Apr 2009
Posts: 21
#6: Sep 14 '09

re: How to write CommandBehaviour.CloseConnection() in VS2008?


dr does not contain property called Command Behaviour
Newbie
 
Join Date: Jun 2009
Location: Whitehall, PA
Posts: 7
#7: Sep 15 '09

re: How to write CommandBehaviour.CloseConnection() in VS2008?


A. CommandBehavior is an enumeration, so it would be CommandBehavior.CloseConnection (no parentheses).

B. The only way I know of to specify the command behavior of a datareader is by passing the value (CommandBehavior.CloseConnection) when calling ExecuteReader() on a given command object.
Reply