Ejemplo n.º 1
0
        public string GetConnectionString(SqlDbConfig config, string user, string password)
        {
            if (String.IsNullOrEmpty(user) || String.IsNullOrEmpty(password))
            {
                if (!(String.IsNullOrEmpty(user) && String.IsNullOrEmpty(password)))
                {
                    throw new Exception("BUG: user and password must both be empty when one is.");
                }

                if (String.IsNullOrEmpty(config.Database.Connection.DefaultUser) || String.IsNullOrEmpty(config.Database.Connection.DefaultPassword))
                {
                    throw new Exception("Please add DefaultUser and DefaultPassword");
                }

                return(GetConnectionString(config, config.Database.Connection.DefaultUser, config.Database.Connection.DefaultPassword));
            }
            else
            {
                var    db   = config.Database;
                string tmp1 = string.Copy(db.Connection.ConnectionString);
                DbConnectionStringBuilder connBuilder = new DbConnectionStringBuilder();
                connBuilder.ConnectionString = tmp1;
                if (connBuilder.ContainsKey(db.Connection.KeyForPassword))
                {
                    connBuilder.Remove(db.Connection.KeyForPassword);
                    connBuilder.Add(db.Connection.KeyForPassword, password);
                }
                if (connBuilder.ContainsKey(db.Connection.KeyForUser))
                {
                    connBuilder.Remove(db.Connection.KeyForUser);
                    connBuilder.Add(db.Connection.KeyForUser, user);
                }
                return(connBuilder.ConnectionString);
            }
        }
Ejemplo n.º 2
0
        static SqlDbConfigsStatic()
        {
            string configPath = ConfigPath;

            if (String.IsNullOrEmpty(configPath))
            {
                throw new ConfigurationErrorsException("Hullo: cant find an entry for dbconfigFile in AppSettings");
            }
            _config = new SqlDbConfigs(configPath);
            _databasesDescription = _config.DatabaselistDescById;

            _dataBases       = _config.Databases;
            _defaultDatabase = _dataBases[_config.DefaultDbId];
        }
Ejemplo n.º 3
0
        public SqlDbConfigs(string SqlDbConfigPath)
        {
            XPathDocument doc = new XPathDocument(SqlDbConfigPath);

            log.Debug("SqlDbConfigPath = " + SqlDbConfigPath);
            nav = doc.CreateNavigator();
            //makes list of available databases:
            XPathNodeIterator dbs  = nav.Select("//SqlDbConfig/Database");
            string            dbId = "";
            int counter            = 0;

            foreach (XPathNavigator db in dbs)
            {
                dbId = db.SelectSingleNode("@id").Value;
                if (counter == 0)
                {
                    mDefaultDbId = dbId;
                }
                //string desc = db.SelectSingleNode("Description").Value;
                string desc = db.SelectSingleNode("Descriptions/Description[1]").Value;
                mDatabaselistDescById.Add(dbId, desc);
                counter++;
            }

            XmlDocument xdoc = new XmlDocument();

            xdoc.Load(SqlDbConfigPath);
            PCAxis.Encryption.SqlDbEncrypter.Decrypt(xdoc);

            mDataBases = new Dictionary <string, SqlDbConfig>();
            foreach (string databaseId in mDatabaselistDescById.Keys)
            {
                string    xPathToDb = "//SqlDbConfig/Database[@id='" + databaseId + "']";
                XmlNode   node      = xdoc.SelectSingleNode(xPathToDb);
                XmlReader xmlReader = new XmlNodeReader(node);
                nav = nav.SelectSingleNode(xPathToDb);

                //mDatabase = new SqlDbConfig(xmlReader,nav);
                mDatabase = SqlDbConfig.GetSqlDbConfig(xmlReader, nav);
                mDataBases.Add(databaseId, mDatabase);
            }
        }