BrockAllen.MembershipReboot icon indicating copy to clipboard operation
BrockAllen.MembershipReboot copied to clipboard

Problem with connection string name (nuget package)

Open Topkapi opened this issue 11 years ago • 12 comments

First of all I must say that I am loving this library. This is a very well thought out membership system. I have, however, found a couple of issues.

When using the MR EF nuget package and instantiating DefaultUserAccountRepository with my own connection string, it does not respect it. It creates a MembershipReboot database no matter what is specified for the name. I investigated it and the problem is not there with the code in the GitHub repo.

In the nuget package, the problem seems to be in the constructor of DefaultMembershipRebootDatabase class. The constructor with connection string does nothing where it should pass it along to the base class.

Another issue I found was that if we specify a schema name, for example, by writing something like new DefaultUserAccountRepository("connString", "SchemaName"), it creates all the MR table twice, once in the dbo schema and once in the schema that has been mentioned.

My advanced apologies if the errors are of my own doing. In that case, please let me know how to configure it properly.

Thank you.

Topkapi avatar Oct 20 '14 13:10 Topkapi

I'd suggest configuring in your DI system a custom instantiation of your DbContext-derived class passing the connection string you want (the DefaultMembershipRebootDatabase has a ctor that will accept one).

Or derive from DefaultMembershipRebootDatabase and pass your connection string to the base and register the custom one with DI.

brockallen avatar Oct 20 '14 14:10 brockallen

check the wiki https://github.com/brockallen/BrockAllen.MembershipReboot/wiki/EF-Configuration

Peter Mbanugo

On Monday, October 20, 2014 3:00 PM, Brock Allen [email protected] wrote:

I'd suggest configuring in your DI system a custom instantiation of your DbContext-derived class passing the connection string you want (the DefaultMembershipRebootDatabase has a ctor that will accept one). — Reply to this email directly or view it on GitHub.

pmbanugo avatar Oct 20 '14 14:10 pmbanugo

@brockallen I am using SimpleInjector and I am already doing what you are saying. Here is the code that I am using:

container.Register<IUserAccountQuery>(()=>new DefaultUserAccountRepository("connectionStringName"));

and it works fine when I am using the code from GitHub repo. The trouble arises when I use the nuget package. When I decompile the source and look at the DefaultMembershipRebootDatabase class, here is what I see:

public DefaultMembershipRebootDatabase(string nameOrConnectionString) { }

I am pretty sure that is "not" the way it should be. It should call the base constructor and pass the connectionstring along. I think it's a bug in nuget package. Can you look at that?

Thank you.

Topkapi avatar Oct 20 '14 19:10 Topkapi

Ok, I think I follow. I'll take a look.

brockallen avatar Oct 20 '14 20:10 brockallen

Ok, I was able to repo this -- something is wrong with the EF NuGet. I'll patch and republish.

brockallen avatar Oct 23 '14 23:10 brockallen

Updated NuGet with v8 -- plz try again

brockallen avatar Oct 24 '14 03:10 brockallen

I tested it. Looks like it accepts context now instead of connection string name but it is working properly. Thank you for taking care of it.

Topkapi avatar Oct 24 '14 18:10 Topkapi

i'm using the nuget version and after many months from last post I see the same bug. it's still a nuget bug? I Was not able to have a connectionString named with a custom name, Otherwise EF continue to create a database (in localhost MSSQL) named MembershipReboot.

The only workaround was to use a connection string named MembershipReboot

Someone continue to have same issue?

mcianc avatar May 02 '15 18:05 mcianc

@mcianc dunno -- i'll take a look when i get chance.

brockallen avatar May 03 '15 16:05 brockallen

Sorry -- I was traveling and just am getting back to these issues.

Here's the ctor for the MR DbContext:

public class MembershipRebootDbContext<TUserAccount, TGroup> : DbContext
        where TUserAccount : RelationalUserAccount
        where TGroup : RelationalGroup
    {
        public MembershipRebootDbContext()
            : this("MembershipReboot", null)
        {
        }

        public MembershipRebootDbContext(string nameOrConnectionString)
            : this(nameOrConnectionString, null)
        {
        }

        public MembershipRebootDbContext(string nameOrConnectionString, string schemaName)
            : base(nameOrConnectionString)
        {
            this.SchemaName = schemaName;
            this.RegisterUserAccountChildTablesForDelete<TUserAccount>();
            this.RegisterGroupChildTablesForDelete<TGroup>();
        }

        // ....
}

If you want to specify a connection string, then you need to create the MembershipRebootDbContext and pass the name you want to use.

brockallen avatar May 26 '15 16:05 brockallen

In addition to steps mentioned in Getting Started article https://pmbanugo.wordpress.com/2014/07/12/getting-started-with-membershipreboot/ I had to perform one more registration

kernel.Bind<DefaultMembershipRebootDatabase>().ToSelf();

NB: I was using NuGet packages

DejanMilicic avatar Jun 12 '15 17:06 DejanMilicic

I think using the MigrateDatabaseToLatestVersion creator overload that takes a connection string name will fix the issue. E.g.

Database.SetInitializer(new MigrateDatabaseToLatestVersion<DefaultMembershipRebootDatabase, BrockAllen.MembershipReboot.Ef.Migrations.Configuration>("myConnName"));

claq2 avatar May 30 '16 14:05 claq2