How to transfer ASP.NET MVC Database from LocalDb to SQL Server?

前端 未结 9 1361
小鲜肉
小鲜肉 2020-12-12 17:20

I created a new ASP.NET MVC 5 project in Visual Studio 2013 (Express for Web) and by default, the project uses LocalDb as its database, but how do you transfer or mi

9条回答
  •  南笙
    南笙 (楼主)
    2020-12-12 17:29

    I had a similar problem, wanting to export from a local db to remote db-server and encountered an error message I couldn't find any information on, but the answer came to me when reading this post, so I'm submitting my answer here in case anyone else has the same problem.

    I set up a solution with Individual User Accounts. VS conveniently creates a db (mdf-file under App_Data) and a connectionstring in the web.config.

    In all my wisdom I thought: "Why not move this to a remote server?" So I did.

    I restored the mdf file on the remote server, expanded it with some simple tables for my web site, created a new connection to the db and added a new ado.net edmx-file, removed the "DefaultConnection" in the web.config and updated the reference to my new connection in the ApplicationDBContext.

    Pressed play, and... no sigar (when trying to log in).

    The entity type IdentityUserLogin is not part of the model for the current context.
    

    Turns out the IdentityDbContex prefers the "DefaultConnection" with the providerName="System.Data.SqlClient" so adding a new edmx-file with the providerName="System.Data.EntityClient" is no good.

    Solution: As warheat1990 suggested, I updated (put back) the DefaultConnections and it's connectionstring value.

    One might argue that I should have two seperate db's (one for users) and one for business stuff, but that's an other discussion.

提交回复
热议问题