ASP.NET MVC 4 Membership Database - sql-server

I have an ASP.NET MVC 4 app. My database is hosted on Windows Azure. My solution has a new SQL Server Database project. I want to start off by adding adding the ASP.NET Membership functionality to this Database [project]. My question is, how do I do that?
I thought it would be a straight forward drag and drop operation. However, I cannot figure out how to do this basic task. All of the online videos I find demonstrate how to to implement the login via the ASP.NET MVC side. However, I don't see anything that shows setting up the Membership tables/sprocs/views and getting them in a SQL Server Database project.
Thank you for any insights.

You can get the script(s) necessary for adding membership to a database using aspnet_regsql in your framework folder (usually %windows%\Microsoft.NET\Framework\v4.0.30319\). An example usage for producing the .sql file would be:
...\v4.0.30319>aspnet_regsql -sqlexportonly MembershipScript.sql
From there, run that script against your database. You may also need to play with the -d <database> flag, but all options can be shown using aspnet_regsql -?. (This includes exporting the necessary tables for session state and other options).
I hope that's what you were asking but if I've misunderstood the question please clarify and I'll do my best to revise the answer

The template for creating an MVC 4 Internet application with forms-based authentication uses both the traditional ASP.NET Membership database with an additional layer on top called SimpleMembership, which has its own database. The SimpleMembership database uses Entity Framework code-first model which creates the database automatically the first time you start the application. Since SimpleMembership uses code-first the database schema can be modified by changing the UserProfile class in AcccountModels.cs. What is your objective for putting these databases that are handled by the application into a separate database project? Unless you are going to bypass SimpleMembership any solution will have to handle two databases.

Related

How can I connect to my SQL Azure-database using Microsoft Silverlight?

I have a database online at Windows Azure. I want to connect to the database and show some tables in Microsoft Silverlight. I have created a Silverlight Application and published the website on Azure here!
How do I connect to my SQL Azure database in Silverlight?
The same way as connecting to any other database!
Personally, I use EntityFramework and create my own service. You can use EF and use RIA Services to create a lot of code for you though if you prefer.
Add an Entity Model to your project, create from existing db, point at your Azure Db, job done. Remember to add your existing IP to the Azure firewall while developing.
EDIT:
Try following this tutorial instead:
http://msdn.microsoft.com/en-us/library/ee707376(v=vs.91).aspx
BUT one thing to watch out for. When you come to the step to add a DomainService, if it hasn't picked up your context you will need to follow the steps listed here:
http://support.microsoft.com/kb/2745294
... which are easy to follow. Delete the TT files and change the model code generation strategy from none to default.
One thing that you can do is create a WCF project, which will act as your Web Role in Azure.
Ideally, you may have 2-3 projects in your solution:
1) Silverlight Project (Presentation Layer)
2) WCF Project (Business Layer)
3) C# Class Project for your Sql Connections (Data Layer)
What you would be able to do is use C# .Net libraries for Sql to connect to your database. You may either execute stored procedures (Can pass in variables), which are cached in memory for faster long-term performance, or Sql queries in a string variable, to pull the exact information you want in custom queries. This would be returned to the WCF Project in which you would be able to perform any custom business-logic and you may begin to package your data into class objects. These objects may be passed back to Silverlight via a Service Reference, and you may use many familiar Silverlight tools to display your information.
The above recommendation may be a more more in-depth than that of the other recommendations, but in cases where you really need control over your data and need to apply business logic, this is a good way.
The easiest way in the world I know of to hook up a SQL Database to a Silverlight application is to use a Visual Studio LightSwitch project. There are ton's of posts on how to do this - http://blogs.msdn.com/b/lightswitch/ . Basically if you make a LightSwitch application (available in VS Professional SKUs and up), it gives you several screen templates to choose from which are all Silverlight (or HTML 5 if you choose). Then you can "attach" to an existing SQL Database such as SQL Azure just fine. And make browse or edit screens around the SQL data.
You can optionally model your own SQL Database and then "publish" it out to SQL Azure.
You can do all of this without writing any code too and provides some good basic functionality.
HTH - Matt

How safe is MVC 4 Default Database?

Im kinda new at MVC 4 and im trying to learn it. I wanted to ask how safe is mvc 4 defaul databases.
When i configure the project and enable role authorization it creates an ASPNETDB.mdf. Can i trust it and its default database in a big project?
As far as i know, by default asp.net creates MSSQL Server Compact database (localfile database). It cannot be used as database for high load project. So you need to migrate it to Normal version of MSSQL Server. To do this, you need to use Aspnet_regsql.exe tool.

Using a new / separate database for forms authentication

Does anyone have a view on whether to use a new separate database for forms authentication users, or is it ok to mix it with your application database?
I could see separation being useful if multiple applications/databases were sharing user authentication, but in my case I have one website/database, and intended to just add the tables/views/sps created by aspnet_regsql.exe to my current application database.
Any views/opinions welcomed. Thank you.
You can mix that db with your database BUT you should not make any changes to the default database tables if you want to use asp.net built in classes that use that database , It means you can only add your tables to that database !
That is OK to have a single Database from which the Forms are to be authenticated. Since the SQL server is a very secure one there will be no problem in having a single database.
But If you want to setup Your custom database for Authentication then Refer the following Links
Using Forms Authentication with a customer database
forms authentication with sql server 2008 database questions

ASP.NET MVC Code-First EF - Possible to use EF without database create permissions?

So I'm working on an ASP.NET project for university. We have to upload our code to a server running IIS and SQL Server 2008. I've written my project using MVC Code-First EF. I understand that the Entity Framework system needs permission to create the database to work properly (you can't just give it an empty database and let it fill it with data). This has created a problem for me since I do not have database creation privileges on the shared SQL Server. Is there any way around this?
As you don't have permissions, it sounds like you'd need to get a DBA to create your database on the server you are trying to deploy to - this could be done from either a database creation script or from a database backup of the db on your dev machine. You can then instruct EF code first not to try to create / update the database automatically by adding this line to your global.asax (or indeed anywhere before you first access the database)
Database.SetInitializer<YourContextType>(null);
You can use an existing database, rather than let EF create one for you. I have done this myself, but admittedly only when using EF Migrations. Otherwise, you run into trouble with missing table exceptions and what not.
When using migrations, just point your connection string to your empty database, create an initial migration to populate the database with your schema and then update the database itself.
See this answer: How do I create a migration for an existing database in EntityFramework 4.3?
.. which include this nice link to getting started with EF Migrations: http://thedatafarm.com/blog/data-access/using-ef-migrations-with-an-existing-database/
All this is available through Nuget, and if you have access to Pluralsight content, I can highly recommend Julie Lerman's video on the topic.
If you don't want to use Migrations, you can still use Code First if you just create the database objects manually using SMMS, but obviously you have the manual work of keeping your model and the database in sync.

Entity Framework and a Dynamics NAV database

I'm currently working on an Intranet application project, using ASP.NET MVC 3.
One of the primary requirements is that all data created with the application must be available in the clients' ERP software as well; they work with MS Dynamics NAV. Accessing the data is not really a problem, as NAV uses SQL-Server as its database.
In fact I already have a working prototype, that uses Entity Framework for data access. The main issue here is that my company also develops quite a lot of custom functionality within the ERP, and thus some of the database tables I have to read from and write to often change. This would not really be a problem in a usual situation, but here, each and every field in the database is marked as not null, a very annoying feature of Dynamics NAV. That means that every field added to a table breaks my code, as Entity Framework tries to insert null when it doesn't know of a field.
Can any of you think of a solution that would not require regenerating the model after each change in the tables ?
Edit : Unfortunately our client still uses version 4.0 of Nav, so webservices are not an option.. I have already developed another application for them (part of a Warehouse management system which runs on mobile terminals), accessing SQL Server directly, but it was not quite the same scale.
If your requirement is to integrate with ERP like Dynamics NAV you should pass all data access through its application server. I think Dynamics NAV expose web services for communication with application server. Accessing its tables directly is way to disaster especially due to transactions and possible deadlocks. EF will make this even worse because you will not be able to tweak queries.
Application integration through database requires full control over SQL generated by all accessing applications.
The answer to your main question is no. The point of database first development is to regenerate your model after each database modification - especially if each database modification is breaking change (another reason why integration through database is not a good choice for you).

Resources