Question

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!



    }
}
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top