internal static void SetupMySqlConnection() { DatabaseConnectionOptions LocalConectionOptions = DatabaseConnectionOptions.GetValues(); MySqlConnectionStringBuilder stringBuilder = new MySqlConnectionStringBuilder { UserID = LocalConectionOptions.User, Server = LocalConectionOptions.Server, Database = LocalConectionOptions.DB, Password = LocalConectionOptions.Password, CharacterSet = "UTF8" }; connection = new MySqlConnection(stringBuilder.ToString()); }
public static DatabaseConnectionOptions GetValues() { if (!File.Exists("connection_settings.json")) { MessageBox.Show("Настройки подключения не указаны.\nСвязь с базой данных невозможна"); return(new DatabaseConnectionOptions()); } DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(DatabaseConnectionOptions)); DatabaseConnectionOptions LoadedOptions = null; using (FileStream fs = new FileStream("connection_settings.json", FileMode.Open, FileAccess.Read)) { LoadedOptions = (DatabaseConnectionOptions)serializer.ReadObject(fs); } return(LoadedOptions); }
public DatabaseConnector() { ConnectionOptions = DatabaseConnectionOptions.GetValues(); InitializeComponent(); DataContext = ConnectionOptions; }