1

How do you change an MVC3 web app to use a remote server for the data context? I tried changing the connection string the in web config (and restarted everything) but it still uses the local SQL database.

Edit: my connection string is below

<add name="ApplicationServices" connectionString="Data Source=zzz.database.windows.net;Initial Catalog=SMS;Persist Security Info=True;User ID=xyz;Password=abc" providerName="System.Data.SqlClient" />

Edit 2: I tried commenting out everything inside the <connectionStrings> tag. The site still works. I'm a bit confused, is the connection set somewhere else?

2
  • Post your connection string. Minus any sensitive password info. Commented Dec 10, 2011 at 19:23
  • 1
    You know it can't do that unless.... you didn't change the right web config or... your connection is coded into the app, not read from the config. Commented Dec 10, 2011 at 19:24

2 Answers 2

1

If you are using Entity Framework code first (which comes with asp.net mvc 3), the name of the database class corresponds with the name of the connection string. For example if you have a class like this:

public class DataContext : System.Data.Entity.DbContext
{
    [...]
}

The name of your connection string should also be DataContext. More info here at step 4.

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

Comments

0

You change the connection string in your web.config. For example if you are using a SQL server your connection string could look like this:

<add name="ApplicationServices"
     connectionString="Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;"
     providerName="System.Data.SqlClient" />

where Data Source points to the name of the remote SQL server, Initial Catalog the name of the database to connect to and User Id and Password seem pretty self explanatory.

Now obviously in your code you will use the ApplicationServices connection string somewhere, so depending on what data access you are using or whether you are using an ORM there might be different places to look for. So if despite changing the connection string in your web.config your code continues to use a local database, well, it's obvious that this is hardcoded somewhere in your code.

Comments

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.