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

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

Related

Restore SQL Server database from a script

I have a database stored on SQL Server with my web site at a regular windows hosting solution. I need to migrate to Azure.
The only backup mean I have is to use SQL Server Management Studio and do a Task -> Generate scripts that saves schema and data in a sql file. I did it and I got a 260Mb file.
My question is about importing that to Azure. Can I do it in Mngt Studio too? How?
Thanks
If you have exported it all to scripts, yes, you can run them against your SQL Database. However, before you do that I'd suggest looking at https://azure.microsoft.com/en-us/documentation/articles/sql-database-cloud-migrate/. It might shed some light on other options that will include verifying compatibility. The BacPac method might be better than the scripts.
To answer the specific question of using SSMS with Azure SQL DB, this article https://azure.microsoft.com/en-us/documentation/articles/sql-database-manage-azure-ssms/ shows how to make the connection.

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

How to migrate a Visual Studio 2012 ASP.Net MVC 4 project to use an SQL Server instance instead of a data file?

When I create a new ASP.Net MVC 4 project with Visual Studio 2012 it puts the data in an mdf file in the project directory.
What I would like to do at this point is to migrate the database to an SQL Server instance gently, keeping all the scaffold stuff provided by the ASP.Net MVC 4 project template (I mean user accounts management etc.)
What would be the right step-by-step way to do this?
How exactly should I change the connection string?
How should I authentify my application in SQL Server in production?
Sorry for a dumb question but I haven't dealt with ASP.Net applications before, in my previous experience (which was with WinForms) all the actual users had a separate SQL Server account and it was pretty straightforward.
The whole User Instance and AttachDbFileName= approach is flawed - at best! Visual Studio will be copying around the .mdf file and most likely, your INSERT works just fine - but you're just looking at the wrong .mdf file in the end!
The real solution in my opinion would be to
install SQL Server - Express (and you've already done that anyway) or any other edition
install SQL Server Management Studio (Express)
create your database in SSMS Express, give it a logical name (e.g. YourDatabase)
connect to it using its logical database name (given when you create it on the server) - and don't mess around with physical database files and user instances. In that case, your connection string would be something like:
Data Source=.\\SQLEXPRESS;Database=YourDatabase;User ID=AppUser;Pwd=Top$ecret
and everything else is exactly the same as before...
For deployment to production, you basically have a number of options:
create deployment SQL scripts yourself and have them executed using sqlcmd or any other useful SQL script runner
use a SQL diff tool like Red-Gate SQL Compare or even the built-in Visual Studio diff tool to determine difference between the database version installed at your client's site, and the new version, and create a single upgrade SQL script from that diff
use the Visual Studio Database Projects and let VS handle the upgrade scripts and deployments. VS database projects craft a model on top of your database - you basically only ever create the CREATE TABLE .... script and the VS tools figure out what needs to be altered, dropped, created fresh
if you're using Entity Framework code-first - look into using the EF code-first migrations to update your database from C# code
What I did is just move the mdf and log file and attach them via SQL Server management studio
The connectstring can be quite simple, something like:
<add name="DefaultConnection" connectionString="Server=YourServer;Initial Catalog=YourDatabaseName;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />

How to set up Database for ASP.NET MVC Application

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.

ASP.NET MVC Tutorials using SQLServer?

How can I use SQLServer (instead of SQL Express) as my database?
I'm trying to go thru the ContactManager tutorial, but I can't seem to get it to use SQLServer - when I pick SQLServer from the "Add New Item" dialog, I get an error telling me that SQL Express isn't installed.
I know I must be missing something basic...
Most tutorials on the ASP.NET site are written in such a way, that you don't have to buy any software to do them. They use Visual Studio Express and SQL Express in their examples.
However, You can still follow along with the tutorial. Just make a few adjustments. Go to the Server Explorer to create a Connection to your SQL Server, and create the database and tables.
Then when it comes to the step of creating the EntityDataModel, create a new connection to the database you just created.
Only SQL Express can attach your database at runtime. If you have a non express version of SQL Server you will need to create the SQL Server using SSMS. If you want the file to physically live in app_data then when asked where to put the database file and the ldf indicate the app_data folder. Once you have created it, it is easy enough to simply add it as an exsisting item, although it can't be checked into source safe without creating obvious issues. I hope this helps.
If you're using a full-fledged instance of SQL Server, you don't need to use the "Add New Item" dialog at all. Rather, connect to your SQL Server instance (via Visual Studio or SQL Server Management Studio), and create the new database there.

Resources