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

前端 未结 9 1363
小鲜肉
小鲜肉 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条回答
  •  旧时难觅i
    2020-12-12 17:25

    Overlord's migration example is spot on. My note at the end was a bit big for a comment, so here are the required changes to the web.config file. An old method on a local drive was to specify

    Data Source=".\[InstanceName]
    

    but may not work on newer interfaces, so replace [.\instance] with [ComputerName\instance] if you migrate forward. This is Visual Studio Pro 2017, SQL Server 2014 & Entity Framework 6.0.

    1st update the connection string.. replace items in brackets with info needed to connect to your database.

    
       
    
    

    next update the entity info.. The [InstanceName] used for SQL Server can be found from [SQL Server Mgmt] console - [Server Properties] - [Advanced] - [Filestream Share Name] & defaults as [MSSQLSERVER].

    
      
         
            
         
       
      
         
      
    
    

    for cloud or other multi-server database migrations, also review [sessionState] settings in web.config & replace [InProc] with [Custom]. [sessionState] comes between [/roleManager] & [/system.web]

    this default for 1 db server

    
      
        
      
    
    

    & this replacement for mult-server or cloud environments

    
    

提交回复
热议问题