예제 #1
0
        /*
         * VALIDO QUE BD TENGO QUE MODIFICAR (SAFTIME/SAFCOM)
         * ARMO LA NUEVA CADENA Y GUARDO EN EL APP.CONFIG
         * PRUEBO LA CONEXION
         */
        public bool SetConnectionString(string server, string catalogo, string usuario, string password, string type)
        {
            bool result = false;

            dataConfigFile = new DataConfigFile();
            try
            {
                // ARMO LA NUEVA CADENA CON LOS PARAMETROS //
                SqlConnectionStringBuilder cadena = new SqlConnectionStringBuilder();
                cadena.DataSource     = server;
                cadena.InitialCatalog = catalogo;
                cadena.UserID         = usuario;
                cadena.Password       = password;

                DBType tipo = (DBType)Enum.Parse(typeof(DBType), type);
                switch (tipo)
                {
                case DBType.Saftime:
                    result = dataConfigFile.SetConnectionString("SaftimeDB", cadena.ConnectionString);
                    break;

                case DBType.SafCom:
                    result = dataConfigFile.SetConnectionString("CNS", cadena.ConnectionString);
                    break;

                default:
                    throw new AppException("El tipo de base de datos: " + type + " no existe.");
                }
            }
            catch (AppException appex)
            {
                throw appex;
            }
            catch (Exception ex)
            {
                throw new AppException("Error no esperado al probar la conexión con la base de datos " + catalogo, "Fatal", ex);
            }
            return(result);
        }
예제 #2
0
        public bool SetConnection(string path)
        {
            dataConfigFile = new DataConfigFile();
            OleDbConnectionStringBuilder builder = new OleDbConnectionStringBuilder();
            bool test = false;

            try
            {
                builder.DataSource          = path;
                builder.Provider            = "Microsoft.ACE.OLEDB.12.0";
                builder.PersistSecurityInfo = false;
                test = dataConfigFile.SetConnectionString("CNS", builder.ConnectionString);
            }
            catch (AppException appex)
            {
                throw appex;
            }
            catch (Exception ex)
            {
                throw new AppException("Se produjo un error no controlado al intentar actualizar la cadena de conexión.", "Fatal", ex);
            }
            return(test);
        }