Question

J'utilise des vues indexées dans ma base de données. Ainsi, le client doit avoir un paramètre de connexion de session pour les appeler. J'utilise ado.net connexion, commande pour appeler des procédures stockées. Chaque fois que je dois appeler une procédure stockée je crée la connexion (je l'espère pool de connexion me permet de le faire rapidement) et exécuter une commande pour appliquer ces paramètres à la connexion en cours.

// some code to create a new connection
 //...
 //... 

 if (connection.State != ConnectionState.Open)
 {
     connection.Open();
 }



    using (var cmd = connection.CreateCommand())
    {
        cmd.CommandType = CommandType.Text;
        cmd.CommandText =
                            @"
                    SET ANSI_NULLS ON
                    SET ANSI_PADDING ON
                    SET ANSI_WARNINGS ON
                    SET ARITHABORT ON
                    SET CONCAT_NULL_YIELDS_NULL ON
                    SET QUOTED_IDENTIFIER ON
                    SET NUMERIC_ROUNDABORT OFF";
        cmd.ExecuteNonQuery();
    }

Autre pensée: ajout de ces paramètres avant chaque appel de procédure stockée:

command.CommandText = 'SET....';
command.CommandText += ' EXEC MyStroredProc @...'; 

Cette solution provoque des problèmes de performance, est-ce pas?

Comment puis-je éviter tout travail supplémentaire si si je dois créer une nouvelle connexion à chaque fois? Comment appliquer ces paramètres automatiquement?

SOLUTION:

ALTER DATABASE [MyDB] 
    SET 
    ANSI_NULLS ON,
    ANSI_PADDING ON,
    ANSI_WARNINGS ON,
    ARITHABORT ON,
    CONCAT_NULL_YIELDS_NULL ON,
    QUOTED_IDENTIFIER ON,
    NUMERIC_ROUNDABORT OFF
scroll top