private void ConnectToDatabase() { cs.LoadConnectionConfig(); if (con != null && con.State == System.Data.ConnectionState.Open) { foreach (Form form in this.MdiChildren) { form.Close(); form.Dispose(); } con.Close(); } if (!cs.IsEmpty()) { con = new NpgsqlConnection(cs.GetConnectionString()); try { con.Open(); ownersService = new OwnersService(con); SetCurrentOwner(ownersService.GetDefaultOwner()); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } } SetMenuChoices(); }
public static string GetConnectionString() { ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration(); connectionConfiguration.LoadConnectionConfig(); connectionConfiguration.Database = "GTSport_Test"; /* * connectionConfiguration.Host = ""; * connectionConfiguration.Port = ""; * connectionConfiguration.UserName = ""; * connectionConfiguration.Password = ToSecureString(""); * connectionConfiguration.SaveConnectionConfig(); */ return(connectionConfiguration.GetConnectionString()); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var config = new ConnectionConfiguration(); Configuration.GetSection("ConnectionConfiguration").Bind(config); services.AddSingleton(config); services.AddFluentMigratorCore() .ConfigureRunner(rb => rb .AddSqlServer() .WithGlobalConnectionString(config.GetConnectionString()) .ScanIn(typeof(Version041920201252).Assembly).For.Migrations() .ScanIn(typeof(Version042520201943).Assembly).For.Migrations()); services.AddSingleton <IProductGroupService, ProductGroupService>(); services.AddSingleton <IProductGroupRepository, ProductGroupRepository>(sp => new ProductGroupRepository(sp.GetRequiredService <ConnectionConfiguration>(), new ProductGroupTableConfiguration())); services.AddSingleton <IPasswordHashing, PasswordHashing>(); services.AddSingleton <IUserService, UserService>(); services.AddSingleton <IUserRepository, UserRepository>(sp => new UserRepository(sp.GetRequiredService <ConnectionConfiguration>(), new UserTableConfiguration())); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0); }