Last post Jan 10, 2016 09:49 AM by Robwarning
Jan 05, 2016 06:50 PM|Robwarning|LINK
web api uses standard a LocalDB database as membership store.
I like to use a remote SQL database for this where I store also my data in. I thought I would be simply a matter of changing connection strings in the web.config but I don't get it working.
this is part of my web.config:
<!--<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-WebApplication5-20160105050122.mdf;Initial Catalog=aspnet-WebApplication5-20160105050122;Integrated Security=True" providerName="System.Data.SqlClient" />-->
<add name="RoosterEntities" connectionString="metadata=res://*/Models.RoosterModel.csdl|res://*/Models.RoosterModel.ssdl|res://*/Models.RoosterModel.msl;provider=System.Data.SqlClient;provider connection string="data source=mssql2.websitelive.net;initial catalog=Warning_Rooster;persist security info=True;user id=*******;password=********;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<!--<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameter value="mssqllocaldb" />
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameter value="RoosterEntities" />
I have added the 6 required tables in this new remote database under the dbo account.
What more do I need to do?
In the early days of ASP.net there was a nice website administration tool to configure security and some more things. is there still something like that?
Jan 06, 2016 01:06 AM|jubbabo|LINK
As a quick check, once you change connectionStrings configuration from 'DefaultConnection' name to 'RoosterEntities' name, did you explicitly use 'RoosterEntities' name for EF context?
connectionString name must be the same as EF context name.
Jan 06, 2016 09:39 AM|Chris Zhao|LINK
If the name of the connection string matches the name of your context then it will be found by DbContext when the parameterless constructor is used. If the connection string name is different from the name of your context then you can tell DbContext to use
this connection in Code First mode by passing the connection string name to the DbContext constructor.
Entity Framework Config File Settings
This topic covers how Entity Framework discovers which database connection to use, and how you can change it. Models created with Code First and the EF Designer are both covered in this topic.
Jan 06, 2016 10:13 AM|Robwarning|LINK
thanks for your answer. I am not behind my development computer right now. But do I understand it right that if I like to use the Database first methode (I am still old fashon and not familiar with code first) I simply have to include the 6 dbo tables used
for membership in my EF view and change the web.config with the right configuration string?
the DbContext will be already be generated when I added the EF model.
I dont have to tell the membership system where the tables are?
Jan 06, 2016 10:20 AM|Robwarning|LINK
Thanks for your reaction. The connection string name is the same as my EF connection. I can access the other tables in the database without problem. the only thing that is puzzeling me is how the membership system knows is has to use this connection.
I have followed the instructions in this link:
http://david.gardiner.net.au/2015/04/entity-framework-6-connection-string.html with the hope it would work.
thing is, I do not have a clu what this defaultConnectionFactory
thing is doing.
Jan 07, 2016 10:24 AM|jubbabo|LINK
in Models folder, Open IdentityModels.cs and ensure your AuthEFContext name is assigning here.
public class APIAuthDbContext : IdentityDbContext<ApplicationUser>
: base("AuthContext", throwIfV1Schema: false)
public static APIAuthDbContext Create()
return new APIAuthDbContext();
where 'AuthContext' is mapping to the same connectionString name in web.config.
In App_Start folder, Open IdentityConfig.cs and ensure 'Create' method calling that Auth Context Class name ('APIAuthDbContext', for this sample)
var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context.Get<APIAuthDbContext>()));
Hope this helps.
Jan 10, 2016 09:49 AM|Robwarning|LINK
Well it took me some time but finally I managed.
The problem is that the connection string for a entity frame work has a different syntax then a normal connection string.
What I did is:
Hope I saves others the time I spend to find out.