/// <summary> /// Gets the format of the parameter, to avoid query the schema the parameter /// format is cached with the type of the parameter /// </summary> /// <param name="command"></param> /// <param name="connectionStringName">Connection String name is needed because if /// we did not already get the format of the parameter we need the connection to /// retrieve the format from the schema.</param> /// <returns></returns> private static String GetParameterFormat(DbCommand command, String connectionStringName) { String typeName = command.GetType().FullName; if (!mParametersFormat.ContainsKey(typeName)) { ConnectionStringSettings cn; if (String.IsNullOrEmpty(connectionStringName)) { cn = ConfigurationRegistry.MainConnectionString; } else { cn = ConfigurationRegistry.ConnectionString(connectionStringName); } DbProviderFactory Factory = DbProviderFactories.GetFactory(cn.ProviderName); using (DbConnection conn = Factory.CreateConnection()) { conn.ConnectionString = cn.ConnectionString; conn.Open(); mParametersFormat.Add( typeName, conn.GetSchema("DataSourceInformation") .Rows[0]["ParameterMarkerFormat"].ToString()); } } return(mParametersFormat[typeName]); }
private static NhibConfigData GetOrCreateConfigData(String configFileName) { NhibConfigData retvalue = factories.SafeGet(configFileName); if (null == retvalue) { //This is the first time we ask for this configuration global::NHibernate.Cfg.Configuration config = new global::NHibernate.Cfg.Configuration(); XDocument doc = XDocument.Load(configFileName); XElement connStringElement = (from e in doc.Descendants() where e.Attribute("name") != null && e.Attribute("name").Value == "connection.connection_string" select e).Single(); String cnName = connStringElement.Value; connStringElement.Value = ConfigurationRegistry.ConnectionString(connStringElement.Value).ConnectionString; using (XmlReader reader = doc.CreateReader()) { config.Configure(reader); } ISessionFactory factory = config.BuildSessionFactory(); retvalue = new NhibConfigData() { Configuration = config, SessionFactory = factory, ConnectionName = cnName }; factories.Add(configFileName, retvalue); } return(retvalue); }
/// <summary> /// In the constructor we creates all the object we need to access the database. /// </summary> /// <param name="connectionName"></param> public ConnectionData(String connectionName) { ConnectionStringSettings cn; if (String.IsNullOrEmpty(connectionName)) { cn = ConfigurationRegistry.MainConnectionString; } else { cn = ConfigurationRegistry.ConnectionString(connectionName); } Factory = DbProviderFactories.GetFactory(cn.ProviderName); Connection = Factory.CreateConnection(); Connection.ConnectionString = cn.ConnectionString; Connection.Open(); TransactionStack.Push(Connection.BeginTransaction()); }