public static DataCommand GetDataCommand(string name, string dataBaseName, DatabaseTypeEnum dataBasetype, bool supportTran)
        {
            DataCommand cmd = dataCommands[name].Clone() as DataCommand;

            cmd.ConnectionStrings  = ConfigManager.GetConfig <ConnectionStringConfigs>().DatabaseList[dataBaseName].ConnectionStringList[dataBasetype.ToString()].ConnectionStrings;
            cmd.SupportTransaction = supportTran;
            return(cmd);
        }
Esempio n. 2
0
 private string[] GetConnectionStringByName(string connectionStringName, DatabaseTypeEnum type)
 {
     try
     {
         return(ConfigManager.GetConfig <ConnectionStringConfigs>().DatabaseList[connectionStringName].ConnectionStringList[type.ToString()].ConnectionStrings);
     }
     catch (Exception ex)
     {
         throw new Exception("Can't find connectionString key: [{0}] in connectionString config.", ex);
     }
 }
 public static DataCommand GetDataCommand(string name, string dataBaseName, DatabaseTypeEnum dataBasetype, bool supportTran)
 {
     DataCommand cmd = dataCommands[name].Clone() as DataCommand;
     cmd.ConnectionStrings = ConfigManager.GetConfig<ConnectionStringConfigs>().DatabaseList[dataBaseName].ConnectionStringList[dataBasetype.ToString()].ConnectionStrings;
     cmd.SupportTransaction = supportTran;
     return cmd;
 }
Esempio n. 4
0
        private static ConnectionSettings BuildConnectionString(DatabaseTypeEnum databaseType)
        {
            string connectionString;
            string server = ConfigurationGet("ServerName", "");

            if (server == "")
            {
                server = ConfigurationGet("Server", "");
            }

            string databaseOrService = ConfigurationGet("DatabaseName", "");

            if (databaseOrService == "")
            {
                databaseOrService = ConfigurationGet("Database", "");
            }
            if (databaseOrService == "")
            {
                databaseOrService = ConfigurationGet("Service", "");
            }
            if (databaseOrService == "")
            {
                databaseOrService = ConfigurationGet("ServiceName", "");
            }
            if (server == "" || databaseOrService == "")
            {
                return(null);
            }
            string user = ConfigurationGet("User", "");

            if (user == "")
            {
                user = ConfigurationGet("DBUser", "");
            }

            string password = ConfigurationGet("PasswordPlain", null);

            if (password == null)
            {
                password = ConfigurationGet("DBPasswordPlain", null);
            }
            if (password == null)
            {
                password = "";
            }

            string port = ConfigurationGet("DatabasePort", "1521");
            string ssl  = ConfigurationGet("SslMode", "Preferred");

            if (databaseType == DatabaseTypeEnum.SqlServer)
            // sql
            {
                if (string.IsNullOrEmpty(user))
                {
                    connectionString = string.Format("Server={0};initial catalog={1};Trusted_Connection=True;",
                                                     server, databaseOrService);
                }
                else
                {
                    connectionString = string.Format("Server={0};initial catalog={1};User Id={2};Password={3};",
                                                     server, databaseOrService, user, password);
                }
            }
            else if (databaseType == DatabaseTypeEnum.MySql)
            {
                connectionString = string.Format("Data Source={0};Database={1};User Id={2};Password={3};SslMode={4};UseCompression=True",
                                                 server, databaseOrService, user, password, ssl);
            }
            else if (databaseType == DatabaseTypeEnum.Oracle)             // oracle
            {
                connectionString = string.Format("Data Source = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = {0})(PORT = {4})))(CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = {1}))); User Id = {2}; Password = {3};",
                                                 server, databaseOrService, user, password, port);
            }
            else if (databaseType == DatabaseTypeEnum.SQLite)
            {
                connectionString = string.Format("Data Source={0}", databaseOrService);
                // Configura
                databaseOrService = connectionString;
                server            = "SQLite";
                user = "******";
                port = "";
            }
            else
            {
                throw new Exception("Unsupported database type '" + databaseType.ToString() + "'.");
            }

            ConnectionSettings ret = new ConnectionSettings();

            ret.Database         = databaseOrService;
            ret.User             = user;
            ret.Server           = server;
            ret.ConnectionString = connectionString;
            ret.Port             = port;
            return(ret);
        }