コード例 #1
0
        private void cmdAceptar_Click(object sender, EventArgs e)
        {
            string connectionString = null;

            switch (TypeDataBase.ToLower())
            {
            case "postgresql":
                var builderPostgreSql = new NpgsqlConnectionStringBuilder
                {
                    Host     = connectionServerTextEdit.EditValue.ToString(),
                    Database = connectionDatabaseTextEdit.EditValue.ToString(),
                    UserName = connectionUsernameTextEdit.EditValue.ToString(),
                    Password = connectionPasswordTextEdit.EditValue.ToString()
                };

                connectionString = string.Format("Server={0};Port=5432;Database={1};User ID={2};Password={3};",
                                                 builderPostgreSql.Host, builderPostgreSql.Database, builderPostgreSql.UserName,
                                                 System.Text.Encoding.UTF8.GetString(builderPostgreSql.PasswordAsByteArray));

                //Probar cadena de conexion para postgresql
                try
                {
                    var connection = new NpgsqlConnection(connectionString);
                    connection.Open();
                }
                catch (Exception ex)
                {
                    XtraMessageBox.Show(ex.Message, "Error de conexión", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                break;

            case "sqlserver":
                var builderSqlServer = new SqlConnectionStringBuilder
                {
                    DataSource     = connectionServerTextEdit.EditValue.ToString(),
                    InitialCatalog = connectionDatabaseTextEdit.EditValue.ToString(),
                    UserID         = connectionUsernameTextEdit.EditValue.ToString(),
                    Password       = connectionPasswordTextEdit.EditValue.ToString()
                };

                connectionString = string.Format("Server={0};Database={1};User ID={2};Password={3};",
                                                 builderSqlServer.DataSource, builderSqlServer.InitialCatalog, builderSqlServer.UserID,
                                                 builderSqlServer.Password);

                //Probar cadena de conexion para postgresql
                try
                {
                    var connection = new SqlConnection(connectionString);
                    connection.Open();
                }
                catch (Exception ex)
                {
                    XtraMessageBox.Show(ex.Message, "Error de conexión", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                break;
            }



            ConnectionStringManager.SaveConnectionString("MainConnection", Cryptography.EncryptStringAes(connectionString));
            ConfigurationManager.RefreshSection("connectionStrings");

            IsConfig = true;
            XtraMessageBox.Show("Se actualizo la información de conexion", "Configuración de conexion", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            Close();
        }
コード例 #2
0
 public static string GetFirstConnectionString()
 {
     return(Cryptography.DecryptStringAes(GetConnectionString(GetFirstConnectionStringName())));
 }