0

My application works perfectly in that I work locally then publish to Azure, Code First handles all the database updates etc

However, I have a method in a class that does a SQL Bulk Copy and to get it working I used a hardcoded connection string

Now I need a neat way to have it 'auto switch' for me. So that when I deploy it automatically uses the LIVE Azure connection string and not the local database

i.e. here is an extract from the line I need to replace with say a application variable

Whats the neatest approach one could recommend for doing this :

            using (SqlBulkCopy sbc = new SqlBulkCopy(@"Data Source=WIN2008-VM;Initial Catalog=AscxxxCF;User Id=exxxer;Password=suxxnx;Integrated Security=True", SqlBulkCopyOptions.Default))
            {

2 Answers 2

2

What about using conditional compilation like

#if (DEBUG)
    // Local connection string.
#else
    // Azure connection string.
#endif

or Web.config transformations?

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

Comments

0

I used, this allowed me to detect within the URL if its running from localhost :

                string url = HttpContext.Current.Request.Url.AbsoluteUri;
                string sConnect = "";

                if (url.IndexOf("localhost") > -1)
                    sConnect = "Data Source=Wxxxx-VM;Initial Catalog=AscxxxxF;User Id=emxxxxr;Password=suxxxxc;Integrated Security=True";
                else
                    sConnect = "Server=tcp:zlxxxxxs.net,1433;Database=AscenxxxxDB;User ID=scoxxxxd;Password=Sxxx;Trusted_Connection=False;Encrypt=True;Connection Timeout=500;";

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.