I have built my MVC 5 project based on entity framework Database First approach by following video tutorials. But what I have obtained is the model. There is nothing in the app_data folder. I want to obtain the .mdf file as well so that I can deploy the database to the azure.
Note: I'm using the server explorer database in VS2013.
I dont think you will be getting any .mdf files on app_data folder.
To deploy your database to Azure:
Right click your database on SQL server, then Tasks->Generate Scripts. On scripting options, select sql azure server
Login to your azure account and create a SQL server and run generated script from the portal by clicking the link below:
while creating your EF connection, use the connection string for your Azure Database like:
At the end you should be ready to use your ORM.
Related
Here are the steps I took:
In Visual Studio, I created an ASP.NET MVC application with authentication
I specified that the database is an Azure SQL Database living in the cloud
So at this point I have a single project in my solution, the web application project for ASP.NET. And I have this database created in Azure with my membership database objects.
Now what I want to do is create a database project in this same solution for more detailed and in depth database development.
I created a database project, and I can easily set to deploy to Azure but I would be "overwriting" the Azure database that was created initially.
How can I "refresh" the database project I just created to reflect the existing database in Azure at this point so I'm not overwriting?
Basically I'm looking to "sync" up the existing Azure SQL Database with the new database project I just created in the solution.
Any way to do this?
Thanks in advance!
Basically what you want is the Schema Compare feature from SSDT (Sql Server data tools)
https://msdn.microsoft.com/en-us/library/hh272690(v=vs.103).aspx
I'm running into an issue when trying to deploy a simple MVC website to Azure. I am using 1 azure website and 1 Azure SQL database.
The boilerplate MVC template in VS2013 uses the Microsoft.AspNet.Identity.EntityFramework provider for the AccountController.cs default controller. When I use this to create the database locally, everything works just fine. However, when I deploy to Azure Websites and update the connection string, the site throws this error:
Cannot open database "master" requested by the login. The login failed.
Login failed for user 'vanillawebsite'.
See full stack trace here: http://pastebin.com/r9jvXgyW (it's massive)
Obviously, on SQL Azure there's no master database, so the default implementation of AspNet Identity Eneity Framework seems to need it though. Manually scripting out the schema to the database doesn't help either (it still attempts to access master for some reason)
Why is it trying to access master database, and how can I work around this?
As said before, SQL Azure has master database and usually when you see this message means that SQL user used in connection string does not have a right to access to the DB in question. Or the DB does not exist, i.e. misspelled name.
I've created a new web application in Visual Studio 2013. I removed the connection string from the web config and ran the application. I was able to register and login on local host. There is no mdf in the App_Data folder. I turned on "show All Files".
Where is the database?
Entity Framework 6 uses LocalDB by default.
It stores your database under you user's folder with the name of your DbContext so
C:\Users\user-name\yourcontextname.mdf
You can read more about how the files are stored and how to access LocalDB from the SSMS from this article: LocalDB: Where is My Database?
How do you deploy a database when you deploy an ASP.NET MVC application to production?
I've created a standard ASP.NET MVC3 application that uses SQL Server 2008 (albeit Express) for my app. I'm using the standard forms authentication stuff that comes with ASP.NET MVC apps.
If I have to re-create my schema, for all my classes (i.e. the non aspnet_* tables), then I have SQL scripts I can run against the production DB; but what about the aspnet_* tables?
Or should I simply upload an ASP.NET MVC empty DB (~10MB) and then run my scripts against it to create my tables? Surely, there must be a better way.
(Once this is solved, I plan to use SQL scripts or DB migrations to handle changes; it's only the question of generating the initial database in production without uploading the ~10MB .MDF that I can't get around, because of the aspnet_* tables.)
You can use aspnet_regsql.exe, located under C:\Windows\Microsoft.NET\Framework[your framework] to generate the schema in your db.
Run:
aspnet_regsql.exe /?
and you will see all of the command-line options this executable takes. -A lets you specify what features (i.e., tables) will get created. If you do not use roles, for example, you may just use -A mp.
You can choose to have it modify your database directly, or instead create a script that you can run. Some details here: http://weblogs.asp.net/lhunt/archive/2005/09/26/425966.aspx
You could run aspnet_regsql utility on your (empty) production database to generate the aspnet_* tables. Check out the MSDN article on the utility.
You can also deploy the db using Visual Studio.
In VS, open the database explorer window
Add a connection to your local db
Right-click on the database and choose 'Publish to Provider'
The db publishing wizard will open
The wizard lets you select which db objects you want to deploy (tables, stored procedures, etc.)
Select the 'Script to file' option, which will create a script that you can run on your prod db
Open SQL Server Management Studio
Connect to your prod db
Open the script file you created with the wizard and execute the script
I have an existing database in SQL Server. I am trying to create an asp.net mvc project around this db.
For this purpose I need to add the db to app_data folder of asp.net MVC project
How do I achieve this?
Note:
The SQL Server is in another system and I do not have rights to install SQL Server Express on my machine as well :(
You don't need to add app_data directory or install SQL Express on your machine. All you need is a connection string allowing you to connect to the remote database.
Data Source=NameOfDbServer;Database=DatabaseName;User ID=User;Password=PWD;Trusted_Connection=False
Once you have the connection string you can start querying the database. The way you do this will depend primary on the technology you would like to use: NHibernate, LINQ to SQL, LINQ To Entities, plain old ADO.NET, ...