What are the challenges you face when working across database platforms? Take the survey
Options

Where does SQL Change Automation store the connection string to the development database

We want to make sure that two different users point to the same development database.  I would expect that this be stored somewhere within the project and be picked up by our source control (GIT).  The only thing that should be different is the user used to connect to the database.  Instead I found that when I pulled the latest changes on a different machine, the database connection was different.  Now, it appears that I have made a royal mess.  The only place I found the connection string was in \obj\projectname.sql.  Normally the obj directory is in the .gitignore so it did not go to the repository.  Is this connection string stored somewhere else?
Tagged:

Best Answer

  • Options
    MikielAgutuMikielAgutu Posts: 29 Silver 1
    edited August 3, 2018 9:26AM Answer ✓
    Hello Mark

    SQL Change Automation stores the connection string in the .sqlproj file for your project. This is under the <DefaultConnectionString> property.

    To set the default connection string:
    • In Visual Studio, right click your project and select properties
    • Under the Debug tab, find the 'Target Connection String' box
    • Click 'Edit...' and select your development database
    • Then click the 'Set As Default' button
    The development database will now be used by default for anyone opening this project from version control.

    However, there may also be a connection string in the .user file for the solution. This will override the default connection string. In order to ensure everyone is using the default connection string from the .sqlproj file:
    • In project properties, under the Debug tab, find the 'Target Connection String' box
    • Click 'Restore Default'
    This will ensure the connection string is pulled from the .sqlproj file.

    You can then edit the target connection string to use different login credentials for the same DB as defined in the default connection string.

    Thanks

    Mikiel Agutu | Software Engineer | Redgate Software

Answers

  • Options
    IbexMarkIbexMark Posts: 9 New member
    There was no <DefaultConnectionString> property .sqlproj file for my project.  I assume that is not set automatically when you first build the project?   I have set it now.
  • Options
    IbexMarkIbexMark Posts: 9 New member
    edited August 3, 2018 6:21PM
    Sorry, now I am having another problem.   On the second PC, it is constantly giving me the "Change Connection" screen   (See attached).  When I attempt to specify the connection, by default it is putting the name of the project as the database name instead of what is specified in the default.  After correcting, if I click "Test Connection" it works; however, when I click 'OK', it goes back to the "Change Connection" screen


    Here is the Default Connection


    Here is what shows when I attempt to Change Connection.  The database name is not coming from the "Default Connection String" but instead, from the project name

  • Options
    IbexMarkIbexMark Posts: 9 New member
    Work-around.  If you edit the Initial Catalog through the project properties display it works.
Sign In or Register to comment.