mvc 5 authentication - where is the database - asp.net-mvc

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?

Related

How to publish to azure

I have an mvc application thats built using the repository pattern. My Database resides in the SmokersTavern.Data folder. I have published the site to azure. On startup the user must logon thereof will be redirected to the Products table. However I get the following error.
It is not allowed to connect to local database when your web app has been published to Azure.
You should create an Azure sql database and connect to it instead. Here's the tutorial for you to refer.
You need to create an Azure resource group deployment project with your Visual Studio web application so that Visual Studio knows where to publish your code. Please take a look at this:
Creating and deploying Azure resource groups through Visual Studio
Although, you are using the 'Publish to Azure' feature, I don't see the resource group configuration in the Solution Explorer pane on the right (based upon the screen capture you provided).
Following this document will walk you through the set-up, configuration, and publishing of your web application to Azure.
I created the app service + sql and in my visual studio I connected to app service created on Azure. My connection string in my config file was not that of the Azure sql db

How to create new project with own database and authentication

I am trying to create a new web MVC project in Visual Studio 2015. I want to use my own database which already exists, and I want to add authentication models and controllers when creating the project.
The issue is:
When I create a new MVC project I can choose the type of authentication but I can't choose what database it uses. So the project is being created with its own local database while I want to use mine so that all necessary tables and DB objects are created in my own database.
I can't even find the LocalDB file created with the project to export the authentication data to my own database.
When I try to connect to the DB it asks me to browse for the mdf file and I have no clue where the file has been created. I did a search in Explorer for the mdf file but found nothing.
I got how to make it working! In case someone has the same problem these are the steps:
Visual Studio creates the defaultConnection - Yes.
But it doesn't create the tables (or probably even the database itself).
So I did the following:
Installed the project (ASP.NET Core Web Application with Framework template) using Individual User Accounts option as authentication.
Then went to appsettings.json and changed the connection string for my own database. (There is no needs to create asp auth tables, only have your own database ready)
I clicked debug and got the website displayed.
Clicked register and registered new user - I got the screen with button to do the migration.
I clicked the button and refreshed the page.
Went to my database and saw all tables have been created in there and the user inserted in the database.
I hope this helps anyone.

entity framework db first

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.

How do I connect to a code-first created localdb database using database explorer?

I have a database in an MVC 4 project that has so far been entirely managed via Code First and Migrations. I now want to go in and change some of the data by hand. How can I connect to the localdb instance using Database Explorer within Visual Studio 2012? The connection string is as follows:
Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-mydb-20120830192823;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-mydb-20120830192823.mdf
I have an App_Data folder in my project, but the .mdf named in the connection string is not in there.
I have tried connecting to '(LocalDb)', 'LocalDb', '.SQLEXPRESS' and various other things in the Add Connection dialog, but nothing seems to work.
Duh, it was '.\SQLEXPRESS' I needed to connect to.

How to add existing SQL Server database to app_data folder of asp.net MVC project

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, ...

Resources