How to set up Database for ASP.NET MVC Application - database

I created an data driven ASP.NET MVC Application locally and it works fine. Within my App_Data Folder of my project i see two databases: ASPNETDB.mdf and myProjectDatabase.mdf.
I uploaded my project files an the webserver, so that I can actually open the website. But I couldn't figure out how to connect my Database that I created locally to that website. My Website uses Authentication so that it is necessary that a user logs in/registers. But because the database is not connected this obviously doesn't work, because the application needs a database to save and retrieve user information.
I'm using Visual Studio 2010 Express and downloaded Microsoft SQL Server Management Studio as well to work with my database. With Microsoft SQL Server Management Studio I already connected to my database with the login information my provider gave me. But how can I import my local databases? Do I need to import ASPNETDB.mdf as well, because that is where the user information are stored?
I would be very thankful for help

What version of SQL Server do you have on your production server? SQL Server Express can attach to those local MDF files. If you're using SQL Server Standard, you'll need to attach them to the SQL Process.
Also, the ASPNETDB.MDB file is the authentication database that is automatically created in your MVC project. That is the DB that stores usernames and passwords, so yes, you will need to move that database over as well.

Related

Store File in Database Server as FILESTREAM

I've used below link to create demo application to store files into database server as FILESTREAM, but in this scenario Web server and database server are on same machine. This is working as expected in local machine.
https://dba-presents.com/index.php/component/content/article?id=59:introduction-to-filestream
But, I want to store files into Database server as FILESTREAM while I am uploading from MVC application, Where my database server and Web server are on different machine.
Please suggest how can I achieve this.

How Visual Studio 2015 Publish Web app and SQL, update DB

starting using VS2015 and publishing to azure websites. I'm developing using a local DB for faster interaction. And I'm publishing Web Application and a SQL Database (Project > publish). But I always getting this error.
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.targets(4276,5): Error ERROR_SQL_EXECUTION_FAILURE:
"CREATE TABLE [dbo].[__MigrationHistory](" There is already an object named '__MigrationHistory' in the database" #ERROR_SQL_EXECUTION_FAILURE.)
Publish failed to deploy.
And it is the same for every table on DB.
How can I somehow just update the tables on the server?
There is another way to work with apps and DB in local machine and later update to the server?
I'm using vs2015, webDeploy 3.6, Windows Azure web app and SQL DB.
I got this solved by removing all files from Properties\PublishProfiles. There was lots of old files from my first publishing attempts. After this I created new profile.

Free SQL Server in Azure

I'm creating a MVC 5 web application with EF 6 Code first. Now it creates a database in the App_Data folder. I want to publish the website to an Azure website. Because this is only the test version of the website, I don't want to pay for it. It will only visited a couple of times a month until it is in production.
Is it possible to run the database something like an access database file? I thought that some kind of functionality existed. I thought the name was SQL Server Compact Edition? But how does it works?
I also thought that you could create a free 20MB sql server database. See this link of the pricing page. Search for 20 in your browser.
http://azure.microsoft.com/en-us/pricing/details/web-sites/
I don't see that option.
Any ideas would be welcome!
Yes, you just have to right click and include in your project.
I write an article for this in Chinese, and this is the English version I found.
Solution for free SQL Server in Azure:
Install two nuget: EntityFrame.SqlServerCompact & Microsoft SQL Server Compact Edition
Put SQL database file (.sdf/.mdf) in APP_Data folder
Put connection string like this to use it:
<add name ="DefaultConnection" connectionString ="Data Source=|DataDirectory|CompactDB.sdf" providerName ="System.Data.SqlServerCe.4.0" />
Publish full project include above SQL database file to AzureWebsites.
It work well and is totally free.
I found the 20Mb free SQL Server option. I still had a website in my subscription that was stopped. When I deleted that, no website or database was there in my subscription anymore. I then created a new website via the custom website option in the azure portal. I then could select (in the wizard) a free 20 MB SQL Server database.
I uploaded my MVC application and the Code First created my database automatically. I don't know why the option wasn't showing up before but now it works.
There's no free version of the SQL Database service. What you may have read is that there's a 1 year free 20MB MySQL database available.
When you're saying that a database it created in the App_Data folder, this uses SQL Server Compact (see Maresh's links) and that is free.
If you want to connect on premise database you need to setup azure virtual network. See the codeproject article
http://www.codeproject.com/Articles/261063/Azure-Virtual-Network-Connecting-Local-Database
there is some alternative way using azure service bus.
http://www.bradygaster.com/post/windowsazurewebsites-onprem-servicebus
Another option would be sql server compact edition.
http://msdn.microsoft.com/en-us/data/ff687142.aspx
see below link also
Support for SQL Server Compact 4.0 on Azure

Browsing an Entity Framework code-first database + Azure Dev Fabric

I have a database created using the code-first approach against SQL Server Express. I'm trying to view the database in Management Studio, but cannot find the database. VS Database Explorer also cannot seem to find it.
I've searched about but cannot find any reference to what I'm after. Is it possible to browse a database running in the dev fabric?
Usually if we create a new database in Visual Studio, it will give us a database file, but it won’t register the database in SQL Server Management Studio. So please manually attach the database file to SQL Server Management Studio. First please find the database file, normally it is under the AppData folder of our project. Then I would like to suggest you to check http://msdn.microsoft.com/en-us/library/ms190209.aspx for instructions on how to attach the database.
Best Regards,
Ming Xu.
Take a look at Scott Gu's blog post on EF Code First and DB Generation: http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx
The Azure Dev Fabric has nothing to do with the DB layer, the connection string handles all this for you i.e. when you deploy to SQL Azure your DB will go there, the only thing that needs changed is the connection string...from localhost (Dev Machine) to SQL Azure connectionn string
HTH

Can't see database listed in SQL Server Import and Export Wizard

(MSSQL newbie alert) I have a number of databases on my machine, some were created using aspnet_regsql, others downloaded from the microsoft ASP.NET MVC 2 tutorials (e.g. http://www.asp.net/mvc/tutorials/mvc-music-store-part-3). The db's created with aspnet_regsql are listed in the wizard dropdown, but the ones I downloaded are not. I tried copying the downloaded mdf's to C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA (where the "good" files are) and restarting the sql server services (both SQL Server (SQLEXPRESS) and SQL Server Browser (SQLEXPRESS), but not luck. The downloaded files also fail to appear on the list that gets populated in the MySQL Migration Toolkit. Strangely, I can used the "invisible" mdf's in the VS2010 web apps created via the tutorials.
It's not enough to just copy the MDF file to a directory. The database has to be attached. See How to: Attach a Database File to SQL Server Express

Resources