using System; using System.Collections.Generic; using System.Data; using System.Text; using log4net; using NHibernate.Connection; using NHibernate.Driver; using NHibernate.SqlCommand; using NHibernate.SqlTypes; namespace SocialAnimal.Persistence { class NoCountDriverConnectionProvider : ConnectionProvider { private static readonly ILog log = LogManager.GetLogger(typeof(NoCountDriverConnectionProvider)); /// /// Initializes a new instance of the class with NOCOUNT OFF specified on the connection /// public NoCountDriverConnectionProvider() { } /// /// Closes and Disposes of the . /// /// The to clean up. public override void CloseConnection(IDbConnection conn) { base.CloseConnection(conn); conn.Dispose(); } /// /// Gets a new open through /// the . /// /// /// An Open . /// /// /// If there is any problem creating or opening the . /// public override IDbConnection GetConnection() { log.Debug("Obtaining IDbConnection from Driver"); IDbConnection conn = Driver.CreateConnection(); conn.ConnectionString = ConnectionString; conn.Open(); IDbCommand cmd = Driver.GenerateCommand(CommandType.Text, new SqlString("SET NOCOUNT OFF"), new SqlType[] {}); using (cmd) { cmd.Connection = conn; cmd.ExecuteNonQuery(); } return conn; } } }