IdentityServer / IdentityServer3.EntityFramework

EntityFramework persistence layer for IdentityServer3
Apache License 2.0
68 stars 97 forks source link

database schema issue #119

Closed bpwood closed 8 years ago

bpwood commented 8 years ago

We have an application with a SQL database, and we're now planning to use IdentityServer3. We want IdentityServer3 to use its own separate schema within the existing application database. I have created a new SQL login, and a new schema (called "identity"), and assigned the new login as the owner of the schema, and also set the user's default schema to "identity". The issue IdSrv does not want to use that schema, and instead always tries to use 'dbo'.

Here's the IdentityServer3 setup:

var efConfig = new EntityFrameworkServiceOptions
    {
        ConnectionString = ConfigurationManager.ConnectionStrings["IdentityServer"].ToString(),
        Schema = "identity"
    };

factory.RegisterConfigurationServices(efConfig);
factory.RegisterOperationalServices(efConfig);
options.Factory = factory.UseInMemoryScopes(Scopes.Get())
                .UseInMemoryUsers(new List<InMemoryUser>())
                .UseInMemoryClients(Clients.Get());

app.UseIdentityServer(options);

I'm seeing the following exception in being thrown in the logs:

System.Data.SqlClient.SqlException (0x80131904): The specified schema name "dbo" either does not exist or you do not have permission to use it.

What have I missed ? Any help would be appreciated

Thanks!

brockallen commented 8 years ago

How are you creating the DB? If you're letting the automatic DB creation happen, then the migrations table needs to be in dbo. This is more of an EF issue than a IdSvr.EF issue. There's also some ~/sql files in the repo you could tinker with to create the DB instead.

bpwood commented 8 years ago

Thanks @brockallen that solved it. I had not created any of the db tables, and was expecting them to be created by EF. I used the operational.sql script to create the Consents and Tokens tables under our 'identity' schema and its working perfectly now.