B2 Security: Authorization (connection string for aspnetchckdbcontext) (Wpf, Xamarin) - chempkovsky/CS2WPF-and-CS2XAMARIN GitHub Wiki

  • Open AspNetBmSecurity\aspnetchckdbcontext.cs-file
  • Change the default constructor
  • instead of
        public aspnetchckdbcontext()
          : base("name=DefaultConnection")
        {
        }
  • it must be
        public aspnetchckdbcontext()
          : base("name=AspNetBmConnection")
        {
        }
  • Add definition In the connectionStrings of the Web.config-file of the Dm04WebApp.csproj-project
    • For Wpf
  <connectionStrings>
    ...
    <add name="AspNetBmConnection"
         connectionString="Data Source=SRV2016SQL2019;Initial Catalog=WpfAspNetBitMasks;Persist Security Info=True;User ID=sa;Password=YOUR_PASSWORD"
         providerName="System.Data.SqlClient" />
    ...
  </connectionStrings>
  • For Xamarin
  <connectionStrings>
    ...
    <add name="AspNetBmConnection"
         connectionString="Data Source=SRV2016SQL2019;Initial Catalog=XamarinAspNetBitMasks;Persist Security Info=True;User ID=sa;Password=YOUR_PASSWORD"
         providerName="System.Data.SqlClient" />
    ...
  </connectionStrings>
  • write a small console app with a code
            Database.SetInitializer(new DropCreateDatabaseAlways<aspnetchckdbcontext>());
            aspnetchckdbcontext db = new aspnetchckdbcontext();
            db.aspnetdashboardDbSet.FirstOrDefault();
            MessageBox.Show("The database was successfully created.", "Done", MessageBoxButton.OK, MessageBoxImage.Information);
            Database.SetInitializer(new CreateDatabaseIfNotExists<aspnetchckdbcontext>());

It will create new database on the server.