Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct syntax for a Flyway connection string to SQL Server?

Running SQL Server 2012 Express on a remote machine, trying to get Flyway up and running. I have a database on pcesqldev.pce.local called Hawk (dbo.Hawk, if that matters) that I want to connect to, and the template from the config file looks like this:

SQL Server        : jdbc:jtds:sqlserver://<host>:<port>/<database>

Note, this is different from other jdbc connection strings I have used with other products - most of them do not include the jtds portion and do include the instance name.

Here's a few connection strings that I have tried, all of which failed:

  • flyway.url=jdbc:jtds:sqlserver://pcesqldev.pce.local:1433/Hawk
    

    Network error IOException: Connection refused: connect

  • flyway.url=jdbc:jtds:sqlserver://pcesqldev.pce.local\SQLEXPRESS:1433/Hawk
    

    Unknown server host name 'pcesqldev.pce.local\SQLEXPRESS'

  • flyway.url=jdbc:jtds:sqlserver://pcesqldev.pce.local/SQLEXPRESS:1433/Hawk
    

    Network error IOException: Connection refused: connect

  • flyway.url=jdbc:jtds:sqlserver://pcesqldev.pce.local:1433/SQLEXPRESS\Hawk
    

    Network error IOException: Connection refused: connect

What am I missing? There must be something obvious, but I can't see it.

Before anybody asks, yes we do have TCP access to the database enabled and it is using port 1433.

like image 986
DaveN59 Avatar asked Jun 26 '15 18:06

DaveN59


People also ask

What database connections can I configure Flyway desktop to use?

Database connections in SQL Server projects in Flyway Desktop can be configured to use: Azure Active Directory Universal with MFA (Multi-Factor Authentication) - learn more about configuring MFA Flyway Desktop uses our SQL Compare technology behind the scenes to understand the differences.

What are SQL connection strings?

What are SQL connection strings? The connection string is an expression that contains the parameters required for the applications to connect a database server. In terms of SQL Server, connection strings include the server instance, database name, authentication details, and some other settings to communicate with the database server.

What is the syntax of the connection string in Ado net?

Learn about syntax of connection strings in ADO.NET. The syntax for each provider is documented in its ConnectionString property. Gets or sets the string used to open a SQL Server database. This article describes how to programmatically specify the client network library in the connection string when you connect to a SQL Server database.

What is the specific connection string syntax for the sqlclient provider?

The specific connection string syntax for the SqlClient provider is documented in its ConnectionString property. For more information on connection string syntax, see ConnectionString. Microsoft SqlClient Data Provider for SQL Server introduced the following connection string builder.


2 Answers

This one got me, and there was not many answers out there on how to format a connection string with an instance name.

Here's what worked for me:

flyway.url=jdbc:jtds:sqlserver://<host>:<port>/<database>;instance=<instance_name>
like image 112
tbonz Avatar answered Sep 22 '22 14:09

tbonz


This did my head in for a bit.

The connection string which I used was this (passed as parameters to flyway on the commandline).

Note also that the mydatabasename needed to already exist.

./flyway migrate -url=jdbc:jtds:sqlserver://localhost:1433/mydatabasename -user=myuser -password=mypassword -baselineVersion=269 -baselineDescription="Base version" -outOfOrder=true -baselineOnMigrate=

A piece that was missing though was that I wasn't running SQL Server Browser and possibly didn't have TCP set up correctly:

From the SQL Server section here. After the installation is complete, enable TCP/IP:

Launch the Sql Server Configuration Manager Go to SQL Server Network Configuration -> Protocols for SQLEXPRESS Enable TCP/IP TCP/IP Properties -> IP Addresses -> IPAll TCP Dynamic Ports: blank TCP Port: 1433 Then enable remote access:

Launch the Sql Server Configuration Manager SQL Server Services -> SQL Server Browser -> Properties -> Service Tab Start Mode: Automatic OK SQL Server Browser -> Start SQL Server -> Restart

like image 38
Damien Sawyer Avatar answered Sep 19 '22 14:09

Damien Sawyer