0

Our web,config uses the same connection name for dev and production, with the only difference being the connection string itself.

I want to create Update-Database commands for dev and production that use a specified connection provided in the command.

I ran PM> get-help Update-Database -detailed but did not see any relevant examples for what I am trying to do.

My question: What params need to be in the ConnectionString? Obviously I need initial catalog, data source, user id and password. Not sure about the others, though. Do I even need the connection name?

        update-database 
    -ConnectionStringName MyConn 
    -ConnectionString data source=10.10.10.20;
                      initial catalog=MyDatabase; 
                      persist security info=False;
                      user id=my_db_user;
                      password=1234;
                      max pool size=200;
                      MultipleActiveResultSets=True" 
                      providerName="System.Data.SqlClient 
1
  • Not sure what you mean. The connection name is the same for both. Is there a way to do this with an environment variable? Commented Mar 23, 2015 at 15:35

2 Answers 2

1

1) Bare minimum is:

  • DataSource / Server / Address / Addr / Network Address
  • Initial Catalog / Database
  • User Id / UID + Password / PWD or Integrated Security = true

2) Default values will be used for other args not specified:

https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring%28v=vs.110%29.aspx

3) ConnectionStringName is required only if you want connection string be taken from connection string defined in your web.config or app.config

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

Comments

1

Have you thought about using web.config transformations instead?

https://msdn.microsoft.com/en-us/library/dd465326%28v=vs.110%29.aspx

In your Web.Release.config file you would have an entry like:

<connectionStrings>
    <add name="MyDbName" connectionString="Data Source=10.10.10.20; Initial Catalog=MyDatabase; User Id=my_db_user; Password=1234;"
         xdt:Locator="Match(name)" xdt:Transform="SetAttributes" />
</connectionStrings>

Using xdt:Transform="SetAttributes" means that you don't need to specify the provider again, only the connection string will change in your transformed web.config

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.