When I create a new ASP.Net MVC 4 project with Visual Studio 2012 it puts the data in an mdf file in the project directory.
What I would like to do at this point is to migrate the database to an SQL Server instance gently, keeping all the scaffold stuff provided by the ASP.Net MVC 4 project template (I mean user accounts management etc.)
What would be the right step-by-step way to do this?
How exactly should I change the connection string?
How should I authentify my application in SQL Server in production?
Sorry for a dumb question but I haven’t dealt with ASP.Net applications before, in my previous experience (which was with WinForms) all the actual users had a separate SQL Server account and it was pretty straightforward.
The whole User Instance and AttachDbFileName= approach is flawed – at best! Visual Studio will be copying around the
.mdffile and most likely, yourINSERTworks just fine – but you’re just looking at the wrong .mdf file in the end!The real solution in my opinion would be to
install SQL Server – Express (and you’ve already done that anyway) or any other edition
install SQL Server Management Studio (Express)
create your database in SSMS Express, give it a logical name (e.g.
YourDatabase)connect to it using its logical database name (given when you create it on the server) – and don’t mess around with physical database files and user instances. In that case, your connection string would be something like:
and everything else is exactly the same as before…
For deployment to production, you basically have a number of options:
create deployment SQL scripts yourself and have them executed using
sqlcmdor any other useful SQL script runneruse a SQL diff tool like Red-Gate SQL Compare or even the built-in Visual Studio diff tool to determine difference between the database version installed at your client’s site, and the new version, and create a single upgrade SQL script from that diff
use the Visual Studio Database Projects and let VS handle the upgrade scripts and deployments. VS database projects craft a model on top of your database – you basically only ever create the
CREATE TABLE ....script and the VS tools figure out what needs to be altered, dropped, created freshif you’re using Entity Framework code-first – look into using the EF code-first migrations to update your database from C# code