From 476a161d9f1e852d5f6a06a5906c8ce3e1c157ba Mon Sep 17 00:00:00 2001 From: Eran Domb Date: Mon, 12 Jan 2004 08:53:13 +0000 Subject: Use ExecuteReader instead of ExecuteNonQuery. We need to use the CommandBehavior parameter, so the connection will be closed if neede. svn path=/trunk/mcs/; revision=21975 --- .../System.Data/System.Data.Common/DbDataAdapter.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'mcs/class/System.Data/System.Data.Common') diff --git a/mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs b/mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs index ba31c526d66..0e3c91269ac 100644 --- a/mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs +++ b/mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs @@ -699,13 +699,21 @@ namespace System.Data.Common { parameter.Value = row [dsColumnName, rowVersion]; } } - + + CommandBehavior commandBehavior = CommandBehavior.Default; if (command.Connection.State == ConnectionState.Closed) + { command.Connection.Open (); + commandBehavior |= CommandBehavior.CloseConnection; + } + IDataReader reader = null; try { - int tmp = command.ExecuteNonQuery (); + // use ExecuteReader because we want to use the commandbehavior parameter. + // so the connection will be closed if needed. + reader = command.ExecuteReader (commandBehavior); + int tmp = reader.RecordsAffected; // if the execute does not effect any rows we throw an exception. if (tmp == 0) throw new DBConcurrencyException("Concurrency violation: the " + commandName +"Command affected 0 records."); @@ -720,6 +728,11 @@ namespace System.Data.Common { else throw e; } + finally + { + if (reader != null) + reader.Close (); + } } return updateCount; -- cgit v1.2.3