ASP.NET MVC 4 Code first migrations after deployment - asp.net

I have a asp.net mvc 4 website. It's database was created using the code-first method. However this website of mine is a blog and i uploaded it to my server. Now i have a few articles and i wanna do some changes - add keywords for example, but this requires changing the model of the articles, if it's local i can easily migrate the new model to the database with the package manager console(VS2012) but how do i do that when it's on my hosting company's server. I didn't find any good results in google. Thank you

I would assume you would just point the connection string that entity framework is using to the database on the remote host rather than your local machine. You're using migrations and I have only used the database initializers (that change the database schema when the model changes), but I can't see it being much different.

Related

Use AZURE BLOB to let user UPLOAD IMAGE (ASP.NET)

Asking for your input. I have created a project athrough ASP.NET - CRUD with EntityFramework
We have to use Azure services for deployment.
This is my setup:
Created Azure SQL database.
Completed the table for the data to be stored (name, age etc.)
Create ASP.NET API and scaffold. Success. Was able to view my data on the localhost.
Created AZURE web app service and publish my API. Checking the url its working so okay.
Completed ASP.NET MVC, called my deployed API app service. Modified controllers, models and views for my webform.
Created AZURE web app service and publish my MVC. So working CRUD, success retrieval of data.
So now working on uploading image.
How will I incorporate the uploading of image for my user(for ex those who will check my project) using blob. Do I need to add the step during my creation of API since I scaffold it? I'm now confused about how I can include my image retrieval from blob storage in my setup or workflow. I just able to work in my crud and still studying for image retrieval.
I have seen tutorials with regards to incorporating blob in asp.net. The problem is that they have only this image upload function in their example. My case is I do want to incorporate it with my CRUD.
Thank you very much for your help.
Do I need to add the step during my creation of API since I scaffold it?
Asp.Net Core's scaffolding won't automatically help you integrate azure blob-related feature code.
If you want to use the relevant code in the auzre blob in the scaffolding, you need to combine the SDK or restapi to implement it yourself.

Xamarin Forms with Azure web app and Azure SQL backend

I am evaluating Xamarin and I am hoping to clarify that I am on the correct path.
We would like to create a Xamarin forms app with offline sync. We are using azure to host the backend database. I have created an Azure web app that uses as Azure SQL database.
I have seen example using easy tables, which seems to create the API’s for you but I cannot find any examples where an Azure SQL database is used.
I have gone to the quick start blade of my azure web app, selected Xamarin.Forms, then chose the backend language of C# and downloaded the project. The project included the TodoItems table as an example. Am I correct in thinking that I need to replace this code with the model of the tables I have in my azure SQL database? And then add the changes back to the web app to expose the tables so that the xamarin forms app can use?
Or am I completely on the wrong track? Should I be using swagger (which I have no experience with) to create the API?
Thanks.
From How to: Define a table controller, you could find that Data Transfer Object (DTO) class that is used to define the table within the SQL database need to inherit from EntityData class. And deriving it from EntityData class is aimed at making it support the system properties. It seems that you have created some tables in your Azure SQL database, if you’d like to expose these existing SQL database tables that does not contain these system properties, please refer to “Using an existing SQL Table” in chapter 3.

Connect Azure database to existing Asp.Net web application

I'm actually working on an university project and have to figure out how to connect my windows azure database to an already existing ASP.net web application project.
The web application should run on smartphones and tablets.
Since this is a group project, we use TFVC to manage the project.
Our client supplied an mysql script that will create the tables needed.
The Database is hosted in Azure and we want to access it through Visual Studio ultimate, so we can reveice data from the DB and integrate it's data in the application.
I also got the connection string, so I could use it if needed.
So my question is:
How can I connect to the database through visual studio and afterwards: how can I access to it? With access I mean, how and where can I use SQL queries in Visual Studio?
I don't really know where to start, whether it is connecting to the DB via code or on another way.
Every kind of help is welcome.
Thank you in advance.
Your question is still quite vague on specifics of what you want to achieve but hopefully this answers it. If not, please provide even more detail on your question.
If you just want to see the DB in Visual Studio and interact with it
Download the Azure SDK
Go to Tools > Connect To Database
A side box will open and you can navigation through Azure then to your database.
Personally I prefer using SQL Server Management Studio, its much more responsive that the UI through Visual Studio.
If you want to connect your application to Azure, as in code an application that talks to a database, then you just need to replace the connection string in your Web.Config to your Azure Connection String. Then either use ADO.NET, Entity Framework or another ORM.
I recommend Entity Framework but it all depends on what your circumstances and project requirements are.
If the DB already has its schema defined get started here:
https://www.asp.net/mvc/overview/getting-started/database-first-development/setting-up-database
If its empty you can use code first:
http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application

asp.net mvc example with db

I know the basics of MVC. But I am looking for an asp.net mvc example with db.
The following example explains the same - but the db is within the app_data folder. But in real practice, as u know, we will use an external SQL server for this
http://www.asp.net/mvc/tutorials/older-versions/movie-database/create-a-movie-database-application-in-15-minutes-with-asp-net-mvc-cs
Can u pl site an example - which explains asp.net mvc with db (just save & retrieve)
It might not completely meet your question but it is quit usual to use Entity Framework or NHibernate to manage your database
See ASP.Net site or the Entity Framework tutorial
Maybe you can find some other answers at that site.
There is no difference on the mvc side. You just have a different connection string to point to a sql server instead of a file inside app_data folder.
Create the same database on you local sql server express and change the connection string to point there. You'll see that will work the same.
In order to make your life easier, you can download SQL ServerManagement Studio Express (this is 2008 version)

Asp.net Membership and Roles Self Contained Web Application

I need to quickly wrap some security around an existing ASP.Net 2.0 web app. After thinking about it for a moment, I remembered that Microsoft created that Membership and Roles paradigm a couple of years back, and that Visual Studio could essentially create everything for you.
Thus I forged forward using the built in ASP.Net Web Site Administration Tool and created a simple little security framework around the application. After setting all of the options, Visual Studio created a nice little SQL Express DB called ASPNETDB.MDF right under the newly created App_Data directory of my website. This works great until you deploy it.
After trying to push this app to my DEV server I realized that it's not going to work unless you have SQL Express installed on the hosting machine. Worse yet, I figured that there's essentially no way this would work under a load balanced environment considering the DB itself will only be isolated to one of the N nodes.
Rather than work to script out the DB and shove it into my existing SQL box...I figured I'd ask the StackOverflow if there is a better solution for simple yet secure ASP.Net websites.
I'd love to maintain the existing model yet have the database become a local, or flat-file DB baked right into the application. For the time being I'm even fine with deploying the flat file with each user or role change to counteract the load balanced sites in PROD.
Is there not a way to create some sort of similar setup with a flat file? I thought that was the point of the App_Data folder?
You could use a custom Role & Membership provider that supports a flat file, like XML. Here is a link to a XML Membership provider, I've seen similar implementations for Roles.
XML Membership Provider
it's not going to work unless you have SQL Express installed on the hosting machine.
Not necessarily. If you still want to use default membership/role providers you can either have the DB server on the hosting machine or have one instance of the DB as a separate server (just change the connection string for providers).
Worse yet, I figured that there's essentially no way this would work under a load balanced environment considering the DB itself will only be isolated to one of the N nodes.
This statement is not really correct in this particular situation.
With load-balancing you will not have isolated database, but rather a separate database server.
I'd love to maintain the existing
model yet have the database become a local, or flat-file DB baked right
into the application. For the time
being I'm even fine with deploying the
flat file with each user or role
change to counteract the load balanced
sites in PROD
If you say that application with proper SQL DB will not scale, I do not understand how flat-file storage can.
You still can keep local SQL Server database and it will work as long as you take responsibility of maintaining the database consistency across different nodes.
In your situation, I would personally use default membership/roles provider as you do now.
But when deploying, just change the connection string to the proper database server.
You will need a database for other stuff anyway, so why not use the same database for all data withing the application (including membership/roles).
Regards.
I found an excellent solution to this here...http://aspnetxmlproviders.codeplex.com/. Using the dynamic XML you can hack out a simple provider based security model in no time flat.

Resources