J'ai commencé à utiliser Microsoft Enterprise Library longtemps en arrière, où dans le cas normal, le fonctionnement DB appels à l'aide des méthodes fournies de classe « base de données » remplir le besoin. Dans certains cas, pour la requête longue, le développeur souhaite définir la propriété CommandTimeout de la classe SqlCommand (ou DbCommand). Cela permettra à la requête d'être exécutée longtemps comme valeur définie dans la commande timeout. Par défaut, le bloc Application Access ne prend pas en charge/n'accepte pas le paramètre CommandTimeout simple dans les appels de méthode (de nombreux exemples de solutions de contournement sont disponibles sur le réseau). Pour obtenir la même chose avec un minimum de modifications, j'ai ajouté une fonction simple nommée "WithCommandTimeOut" en prenant le paramètre timeOutSecond dans la classe "Microsoft.Practices.EnterpriseLibrary.Data.Database" qui renvoie la même instance de la classe "Database". Reportez-vous à l'extrait de code mis à jour ci-dessous pour les modifications de code. Espérons que cela va résoudre le problème d'expiration.
//Class Level Static Variables
//Used to reset to default after assigning in "PrepareCommand" static method
static int DEFAULT_COMMAND_TIMEOUT_RESET = 30;
//Default value when "WithCommandTimeOut" not called
static int COMMAND_TIMEOUT_FOR_THIS_CALL = DEFAULT_COMMAND_TIMEOUT_RESET;
public Database WithCommandTimeOut(int timeOutSeconds)
{
COMMAND_TIMEOUT_FOR_THIS_CALL = timeOutSeconds;
return this;
}
protected static void PrepareCommand(DbCommand command, DbConnection connection)
{
if (command == null) throw new ArgumentNullException("command");
if (connection == null) throw new ArgumentNullException("connection");
//Here is the magical code ----------------------------
command.CommandTimeout = COMMAND_TIMEOUT_FOR_THIS_CALL;
//Here is the magical code ----------------------------
command.Connection = connection;
//Resetting value to default as this is static and subsequent
//db calls should work with default timeout i.e. 30
COMMAND_TIMEOUT_FOR_THIS_CALL = DEFAULT_COMMAND_TIMEOUT_RESET;
}
Ex.
Database db = EnterpriseLibraryContainer.Current.GetInstance(Of Database)("SmartSoftware");
db.WithCommandTimeOut(0).ExecuteDataSet(CommandType.Text, query);
Merci, c'est ce que je recherchais! –