Asp.Net MVC development with Visual Studio LocalDB - asp.net-mvc-4

I am currently studying software development and for a project I will be developing a database driven application in Asp.Net MVC. I am completely new to MVC but have experience in Asp.Net Web Forms.
I have done a small app using the Entity Framework Code First approach using the Local db. My question is if I start a website using the localdb can i then transfer the database to a seperate sql server database. Also if the database is not a localdb, can code first still create the tables in the seperate database as in the localdb
Thanks

Yes, definitly, you can do that.
When you want to migrate simply :
Generate script from localdb and run it on sqlserver
Create a new connection string to point to the new SQLserver database.
This should do the job:
Here is tutorial that might help you.

Related

asp.net MVC 4.0 membership database

I'm familiar with aspnet_regsql.exe to create a membership database in asp.net web forms. but i am not aware about MVC4.0(visual studio 2012) membership. what should i do to have these membership table in SQL server management studio 2012.
The tables are created automatically the first time you try to register a user. If you want to configure a remote database, then you can use database migrations to generate a script to execute to create the tables afterwards.

Deploy database to web hosting MVC4 - VS 2012 Express for Web

I've created a small website and now want to deploy it to web hosting www.citynetwork.se. I've successfully deployed the MVC4 code developed using .Net 4.0 framework. The connection string I'm using currently for localhost is;
<add name="EventtavlanContext" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=Eventtavlan1;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\Eventtavlan1" />
It works perfect at localhost but how should I deploy the database to the web hosting?
As my web hosting provides support for MySQL and MS SQL so should I
create a new database on web hosting and create/deploy the schema
only? How would I do that?
Should I include the database from App_Data folder while
publishing from VS 2012 to the web hosting and change the connection
string only? What would be the new connection string then?
Or is there any other way of deploying the database? Can somebody guide me
with the easiest way?
Thank you.
Yes, create a new MS SQL database at the hosting provider. If you want to deploy the schema you can do that easily from Visual Studio using the dbDacFx provider. See http://msdn.microsoft.com/en-us/library/dd394698.aspx#dbdacfx .
No, don't include the .mdf in App_Data. You can't use a LocalDB database when running in IIS. When you create the database at the hosting provider they should provide the connection string.
Easiest way if you only want to deploy schema is dbDacFx provider as I mention in #1. That page I link to also mentions other options. If you're using Code First, Migrations is a good way to deploy. See this tutorial: http://www.asp.net/mvc/tutorials/deployment/visual-studio-web-deployment/introduction

Web Deploy does not update SQL database schema changes

I am newer to Visual Studio 2012 and MVC4, and have a development project of a website using C# and MVC4 and SQL server 2012.
The Publish using web deploy works for the website portion of the project, but it does not automatically update the database portion (schema). If I right click the database portion of the project in VS2012 and click Publish, then the database schema is updated properly. I am only interested in schema updates. What could be wrong?
I programmed my development system to use Web Deploy 3.0. Here is a summary of my configuration:
Computer running win8 x64
SQL Express 2012 as my database server, running as the default instance (i.e. at localhost, NOT as .\SQLEXPRESS)
IIS Express 8 as my webserver, using the "Default Web Site" site (localhost)
Visual Studio 2012 Pro using MVC4 and C#
Web Deploy 3.0
The latest dates are all applied to the software
I programmed an SQL server user WDeployAdmin for managing the database updates and gave it full permissions over the database being used for the website. I also tried using Integrated Security (my administrator login) but that does not help.
I can correctly update the Default Web Site (views and controllers etc) using the Publish feature in VS2012 which uses Web Deploy 3.0.
When I use the Test Connection feature of the publishing setup options, it correctly connects to the database, and that certainly works fine when I do a separate Publish DB operation (right-click DB project, click Publish, and then pick my profile) for that part of my project.
So why doesn't the standard website Publish feature include the database schema updates? The standard website Publish always shows an empty change to database when the schema changes (e.g. a table or a stored procedure).
I have read through much MS docs but nothing is apparent to me.
Any help is appreciated,
Bruce

Visual Studio database project won't deploy to SQL Azure

I've ran into problem very similar to this. I have a .dbproj Visual Studio database project. It deploys just fine in SQL Server Express. Now I want to deploy it to SQL Azure - I change the connection parameters but deployment fails with the following text:
C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\TeamData\Microsoft.Data.Schema.TSqlTasks.targets(120,5): Error Deploy01234: The target database schema provider could not be determined. Deployment cannot continue.
Done executing task "SqlDeployTask" -- FAILED.
Is deploying .dbproj projects to SQL Azure supported? How do I make Visual Studio deploy the database into SQL Azure? What are other ways to achieve more or less the same results except recreating the database manually using Azure portal?
If you are using Visual Studio 2012, you can now create a Database project and go to Properties - set its Target Platform to SQL Azure in Project Settings tab. Also you can configure the setting for dacpac output. Use this file to import directly as a new SQL Azure database.
As far as I know, Database projects are still not supported by Windows Azure. You can deploy the project to a local SQL server and then use the "Generate Scripts" feature to port the database to SQL Azure. See this link.
An easy solution is to create the database locally and use the SQL Azure Migration Wizard to do the migration up to SQL Azure. It works very well in just a few clicks (and will fix common errors).
Database projects don't work with SQL Azure. What I do is before deploying, create a brand new database on local server (to ensure it is up to date with no dev scripts), and then sync that database to Azure with RedGate SQL Compare. I do a backup first with RedGate SQL Azure Backup.
When we first built DB projects, SQLAzure was still going through its identity crisis and didn't know what it wanted to be. ;)
DBProjects support a significant superset of capabilities vs. SQLAzure. Therefore, it's quite possible that it'll create scripts that won't run against SQLAzure.
I know that the team who took-over the DBProject tooling were looking at restricting the database project generators to output SQLAzure-compatible scripts, but I don't know how far they got or whether they decided to proceed.
I echo dunnry's suggestion above and use the SQL Azure Migration Wizard or Jeremy's and use SQL 2008 R2 and generate Azure-compatible scripts.

aspnet_regsql.exe and MVC

Can someone explain what aspnet_regsql.exe is really used for?
When I create a standard ASP.NET MVC project in VS2008 and register a user, I get the db created with corresponding asp.net membership tables etc.
This uses the SQL Server Express 2005 as standard.
The forums I have found states that aspnet_regsql.exe is used when one is migrating the created SQL Server Express db to a SQL Server, fx. to a hosting server. I am right about this?
But is this change a global change, meaning that next time I start a new MVC project or standard Win Forms project and add a db, it will use SQL Server as provider and not SQL Server Express? Or is this aspnet_regsql.exe only used on a project basis?
Like you say, the aspnet-regsql will create the tables into any (Express or not) version of SQL Server. I -think- your main question is how do you know which database you're attaching to, right? If so, then that is handled in your web.config file in the "Membership" provider area. What I do is use a SqlMembershipProvider for my development (utilizing the tables created with aspnet_reqsql) and then switch to ActiveDirectoryMembershipProvider for production.
MSDN Article on aspnet_reqsql
aspnet_regsql.exe is a utility designed to prepare a database to work with asp.net providers. These providers provide services to asp.net applications such as user membership, roles, and profile management and require a database that adhere to specific schemas.
By running this application you can alter an existing database to adhere to these schemas or create the default database for these services (aspnetdb.mdf?).
I believe that the utility might also prepare some of the intrinsics for provider usage.