0

Sorry, for a beginner question, but I cannot figure out how to have two connections strings and use them depending on host. This is my settings from Web.config:

    <add name="SniffstersEntitiesLocal" connectionString="Data Source=127.0.0.1;initial catalog=Sniffsters;integrated security=True;" providerName="System.Data.SqlClient" />

    <add name="SniffstersEntities" connectionString="Server=tcp:huucyucfp0.database.windows.net,1433;......

And then I would like in my Context file to have something like:

if (Iam on local host)
myConnectionString = SniffstersEntitiesLocal
else 
myConnectionString = SniffstersEntities

public class SniffstersContext : IdentityDbContext<ApplicationUser>
{

    public SniffstersContext()
        : base("SniffstersEntities", throwIfV1Schema: false)
    {

      YOUR HELP IS APPRECIATED!



    }
}

1 Answer 1

1

Two ways you could do this.

1) Since you have to publish to Azure use transforms http://msdn.microsoft.com/en-us/library/dd465326(v=vs.110).aspx

2) if that isn't possible, get the Host from the Request object: if(Request.Url.Host == "localhost") do localhost connection else do azure connection

Of the two, I'd recommend the transforms.

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

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.