How to link a SQL Server database to a source control system

Applies to

ApexSQL Source Control

Summary

This article explains how to link a database to the source control repository using the Source control setup window

Description

Using ApexSQL Source Control, a SQL Server Management Studio add-in, developers can link a database to the source control repository directly from SQL Server Management Studio.

Linking process

  1. Right-click on the database in the Object Explorer pane, and from the context menu, select the Link database to source control option:

    The Link database to source control command in the Object Explorer pane

  2. The Source control setup window will be displayed:

    The Connection tab in the Source control setup window

The Source control setup window consists of five steps (tabs):

  1. Connection type tab
  2. Development model tab
  3. Object filtering tab
  4. Script Options tab
  5. System login tab

Connection type tab

The Connecction tab in the Source control setup window whn the Native option is chosen

ApexSQL Source Control supports the two types of connection to the source control repository:

  • Native
  • Working folder

If the Native option is chosen, then the source control system must be chosen as well. ApexSQL Source Control natively supports five source control systems:

  • Git
  • Mercurial
  • Perforce
  • Subversion
  • Team Foundation Server

Supported source control systems under the Connection tab in the Source control setup window

The Working folder feature can also be used to link a database to any folder in the file system. This feature is convenient, e.g., evaluating purposes or linking the database to the local repository folder created by third-party source control clients.

Development Model tab

One of the two standard development models must be specified for working with the source control systems:

  • Dedicated
  • Shared

The Develppment model tab in the Source control setup window

Quick tip icon

Quick tip:

When you link a database on which multiple developers will work at the same time, the Shared database model is suggested

Object filtering tab

This step provides a possibility to exclude objects not to be linked to source control. It is possible to exclude specific objects, exclude objects by owner or type. Learn more

The Object filtering tab in the Source control setup window

Script options tab

This step of the Source control setup window is about setting the Ignore comparison and the Synchronization options for the selected database. More about options under this tab is explained in the Script comparison and synchronization options in ApexSQL Source Control article

The Script tab in the Source control setup window

System login

Connecting to a source control repository requires appropriate login information to be provided as well as some additional information specific to the chosen source control system.

Here’s how login forms and the repository string specific to each source control system look like:

Git

The System login tab in the Source control setup for Git source control system

The Repository path form:

<protocol>://<hostname>:<portnumber>/<Git server name>/<repository>

  • <protocol> – can be HTTP, HTTPS or SSH
  • <hostname> – the machine hostname, a NetBIOS name or a DNS  machine name that hosts the Git Server
  • <portnumber> – port 8443 is used by default
  • Using <Git server name> in the repository path is mandatory
  • <repository> – the name of the Git repository to connect to
Quick tip icon

Quick tip:

When connecting to a Git, Mercurial or Subversion repository hosted in the local machine file system, the following form of the repository path is advised:
<LocalPathToRepository>\<repository>

Mercurial

The System login tab in the Source control setup for Mercurial source control system

The Repository path form:

 <protocol>://<hostname>:<portnumber>/<repository>

  • <protocol> can be HTTP, HTTPS or SSH
  • <hostname> – host machine, NetBIOS, or DNS name
  • <portnumber> – port 8443 is used by default
  • <repository> – the name of the Mercurial repository to connect to

Perforce

The System login tab in the Source control setup for Perforce source control system

The Repository path form:

<protocol>://<hostname>:<portnumber>

  • <protocol> – can be TCP which is the default, or SSL
  • <hostname> – the machine hostname, a NetBIOS name or a DNS machine name that hosts the Perforce server
  • <portnumber> – port 1666 is used by default

Subversion

The System login tab in the Source control setup for Subversion source control system

The Repository path form:

<protocol>://<hostname>:<portnumber>/svn/<repository>/

  • <protocol> – can be HTTP, HTTPS, SVN or SSH
  • <hostname> – host machine, NetBIOS, or DNS name
  • <portnumber> – port 8443 is used by default
  • <repository> – the name of the Subversion repository to connect to

Team Foundation Server (Azure DevOps Server/Services)

The System login tab in the Source control setup for Azure DevOps Server/Services source control system

The meaning of the fields:

  • TFS server – the path to the selected source control repository. It requires to be entered in the following form: <protocol>://<hostname>:<portname>/tfs:
    • <protocol> – can be HTTP or HTTPS
    • <hostname> – host machine, NetBIOS, or DNS name
    • <portname> – port 8080 is used by default
    • Using /tfs in the repository path is mandatory
  • Project – the folder in the Team Foundation Server (Azure DevOps Server/Services) that stores the source control files
Quick tip icon

Quick tip:

When connecting to Azure DevOps Services, use the alternate username and Token created under user profile options. The correct repository path is:

After the database is linked, you can initially commit all objects to the repository from the Action center tab. The database object status will be refreshed and shown as linked via the appropriate icon:

Icons for linked database and objects in the Object Explorer pane