0

I created a mvc5 asp.net website that connects to sql server database. Looks like when ever I register a user through this website, user is created to database called DefaultConnection that is located at C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA.

But my config file is not pointing to this. My config file is pointing to a proper database at certain server. Also my connection has different name like

<connectionStrings><add name="TestEntities"....

And when I run my website it correctly bringing info from this database. Problem is only when I register a user.

4

1 回答 1

0

The membership provider doesn't know to use a connect string named TestEntities, by default it uses a connection string named "DefaultConnection" and seemingly has a fallback in case that isn't present. (See this to be more precise: ASP.NET Configuration File Hierarchy and Inheritance)

You could:

  1. change your connection string name to DefaultConnection
  2. copy your connection string and call the copy DefaultConnection
  3. override the connection string name used by Entity Framework under the hood using the config below. I believe you can also override the connection string name used by creating you own DBContext.

Personally, I'd go with option 2, provides flexibility if you ever want to move the user tables out to a seperate database.

于 2014-12-12T15:34:27.160 回答