Example #1
0
        /// <summary>
        /// Almacena la configuracion con los datos que se pasan como parametros.-
        /// </summary>
        /// <param name="pCnnString">Coneccion</param>
        ///<param name="pAppend">Agrega nuevo elemento</param>
        public bool SaveSetting(CnnString pCnnString)
        {
            bool isNew = false;

            if (_DataBaseConnections.Connections.Any <CnnString>(c => c.Name.Equals(pCnnString.Name, StringComparison.OrdinalIgnoreCase)))
            {
                //modifico la configuracion .-
                CnnString cnn = _DataBaseConnections.Connections.First <CnnString>(c => c.Name.Equals(pCnnString.Name, StringComparison.OrdinalIgnoreCase));

                if (cnn.Name != null)
                {
                    cnn.Password               = pCnnString.Password;
                    cnn.DataSource             = pCnnString.DataSource;
                    cnn.User                   = pCnnString.User;
                    cnn.WindowsAutentification = pCnnString.WindowsAutentification;
                    cnn.InitialCatalog         = pCnnString.InitialCatalog;
                }
                isNew = false;
            }
            else
            {
                //Almaceno la configuracion .-
                _DataBaseConnections.Connections.Add(pCnnString);
                isNew = true;
            }



            _CurrentCnnString = pCnnString;
            _DataBaseConnections.Save();
            return(isNew);
        }
        internal void Load()
        {
            try
            {
                IsolatedStorageFile userStore = IsolatedStorageFile.GetUserStoreForAssembly();

                //Si no hay datos para este usuario
                if (userStore.GetFileNames(DATABASE_CONFIG_FILE).Length == 0)
                {
                    //Limpio el diccionario por si contien algo
                    //_Connections.Clear();
                    return;
                }
                //Abro el stream con la informacion serializada del diccionario desde el IsolatedStorage
                IsolatedStorageFileStream userStream = new IsolatedStorageFileStream(DATABASE_CONFIG_FILE, FileMode.Open, userStore);
                _Connections = DeSerializeDictionary(userStream);
            }
            catch (FileNotFoundException)//si ocurre algun error construyo una coneccion por defecto
            {
                CnnString cnn = new CnnString();
                cnn.DataSource             = "DataSourceEmty";
                cnn.Name                   = "ConnectionName";
                cnn.Password               = String.Empty;
                cnn.User                   = "******";
                cnn.WindowsAutentification = true;
                cnn.InitialCatalog         = String.Empty;

                _Connections.Add(cnn);
                Save();
            }
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public DataTable GetDataBases()
        {
            CnnString cnn = GetCnnStringToMaster(_CurrentCnnString);

            using (SqlConnection wCnn = new SqlConnection(cnn.ToString()))
                using (SqlCommand wCmd = new SqlCommand())
                {
                    try
                    {
                        wCnn.Open();
                        wCmd.Connection  = wCnn;
                        wCmd.CommandType = CommandType.StoredProcedure;
                        wCmd.CommandText = "sp_databases";

                        DataSet        wDs = new DataSet();
                        SqlDataAdapter wDa = new SqlDataAdapter(wCmd);

                        wDa.Fill(wDs);
                        wCnn.Close();
                        return(wDs.Tables[0]);
                    }
                    catch (SqlException ex)
                    {
                        throw ex;
                    }
                }
        }
Example #4
0
        /// <summary>
        /// Permite leer nuevamente el archivo de configuracion donde esta el acceso a la BD para recargar la coneccion.-
        /// </summary>
        public void InitializeConfig()
        {
            try
            {
                _DataBaseConnections.Load();
                if (_DataBaseConnections.Connections.Count > 0)
                {
                    _CurrentCnnString = _DataBaseConnections.Connections[0];
                }
            }

            catch (FileNotFoundException)
            {
                string msg = "No se encuentra el archivo de configuracion de base de datos:";
                throw new System.Exception(msg);
            }
            catch (System.Security.Cryptography.CryptographicException e)
            {
                _CurrentCnnString.Password = String.Empty;
                throw new DataBaseExeption(e, _CurrentCnnString);
            }
            catch (Exception)
            {
                string msg = "Verifique que el archivo de configuracion tiene seteado el archivo de conecciones a la base de datos.-";
                throw new System.Exception(msg);
            }
        }
Example #5
0
        public CnnString CreateConnection()
        {
            _CurrentCnnString = new CnnString();

            _DataBaseConnections.Connections.Add(_CurrentCnnString);

            return(_CurrentCnnString);
        }
Example #6
0
        /// <summary>
        ///
        /// </summary>
        public Metadata(CnnString cnnString)
            : base(String.Empty)
        {
            _Tables          = new Tables();
            _StoreProcedures = new StoreProcedures();
            _DataBaseServer  = new DataBaseServer(true);

            _DataBaseServer.CurrentCnnString = cnnString;
        }
Example #7
0
        private static CnnString GetCnnStringToMaster(CnnString pCnnString)
        {
            CnnString _CnnStringToTest = new CnnString();

            _CnnStringToTest.DataSource             = pCnnString.DataSource;
            _CnnStringToTest.InitialCatalog         = "master";
            _CnnStringToTest.User                   = pCnnString.User;
            _CnnStringToTest.Password               = pCnnString.Password;
            _CnnStringToTest.WindowsAutentification = pCnnString.WindowsAutentification;
            return(_CnnStringToTest);
        }
Example #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pServerName"></param>
        /// <param name="pUserName"></param>
        /// <param name="pPassword"></param>
        /// <param name="pWindowsAutChecked"></param>
        /// <returns></returns>
        private static CnnString GetCnnStringToMaster(string pServerName, string pUserName, string pPassword, bool pWindowsAutChecked)
        {
            CnnString _CnnStringToMapper = new CnnString();

            _CnnStringToMapper.DataSource             = pServerName;
            _CnnStringToMapper.InitialCatalog         = "master";
            _CnnStringToMapper.User                   = pUserName;
            _CnnStringToMapper.Password               = pPassword;
            _CnnStringToMapper.WindowsAutentification = pWindowsAutChecked;
            return(_CnnStringToMapper);
        }
Example #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pCnnString"></param>
        /// <returns></returns>
        public static bool TestConnection(CnnString pCnnString)
        {
            using (SqlConnection wCnn = new SqlConnection(pCnnString.ToString()))
            {
                try
                {
                    wCnn.Open();

                    wCnn.Close();
                    return(true);
                }
                catch (Exception ex)
                {
                    throw new DataBaseExeption(ex, pCnnString);
                }
            }
        }
Example #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pException"></param>
        /// <param name="pCnnString"></param>
        public DataBaseExeption(Exception pException, CnnString pCnnString)
        {
            _CnnString = pCnnString;


            if (pException.GetType() == typeof(System.Security.Cryptography.CryptographicException))
            {
                _Msg = "La password encriptada en el archivo de configuracion fue violada. "
                       + Environment.NewLine + "Reescriba su clave y guarde su configuracion";
            }
            if (pException.GetType() == typeof(SqlException))
            {
                System.Data.SqlClient.SqlException ex = (System.Data.SqlClient.SqlException)pException;
                //ex.Number == 18456 Login fail
                _Msg = pException.Message + Environment.NewLine + "Vuelva a ingresar la informacion de conección";
            }
            if (pException.GetType() == typeof(System.IO.FileNotFoundException))
            {
                _Msg = pException.Message;
            }
        }
Example #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pServerName"></param>
        /// <param name="pUserName"></param>
        /// <param name="pPassword"></param>
        /// <param name="pWindowsAutChecked"></param>
        /// <returns></returns>
        public static bool TestConnection(string pServerName, string pUserName, string pPassword, bool pWindowsAutChecked)
        {
            CnnString cnn = GetCnnStringToMaster(pServerName, pUserName, pPassword, pWindowsAutChecked);

            return(TestConnection(cnn));
        }