0

I follow the this tutorial step 1- 5 and check it locally and its working great http://www.asp.net/mvc/tutorials/mvc-5/introduction/getting-started Now I convert the solution to azure and publish it and I was able to see the Asp page but when I navigate to the movies (in the URL) I got error ,i guess that this is related to the data base ,in the app data folder I have the local DB there is a way to convert it azure DB or storage that I will able to update the data from azure url and not from local?

1 Answer 1

1

The best way to do this is to create an Azure SQL Database. Note, in the tutorial, you can probably stop at Step 4, since EF Code First will take care of generating the schema.

Then you'll want to set up Web.config transforms to your Web.Debug.config and Web.Release.config files, and Visual Studio will automatically change your connection string when you deploy.

Inside your Web.config, find your connection string:

<connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=localhost;Initial Catalog=DatabaseName;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
</connectionStrings>

(note your actual connection string might be different, if using SQL Express or something)

Then add the following to Web.Debug.config and Web.Release.config:

<connectionStrings>
    <add name="DefaultConnection" connectionString="Server={the connection string from the Azure portal}" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>

Make sure the connection string name is the same as in Web.config, so it knows which one to replace.

Now when you run the project locally, it'll connect to your local database. When you deploy to Azure, it'll connect to the Azure SQL Database.

Sign up to request clarification or add additional context in comments.

2 Comments

HI Mfanto, Thanks voted up,Ok I put the server name after I create the DB but what is locator Match(name) from where should I find it?2. when I create DB I in azure (silver light) I give a name (I can create many table) so where in the connection string I should put the table name ?
The Match(name) part is to match the connection string by name. You don't need to change anything there. All you need to do is update the connectionString to the connection string from Azure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.