7

My working SQL Server 2014 connection string is:

Data Source=localhost;Initial Catalog=myDb;Integrated Security=True;

I need to install a new instance of SQL Server 2016 on the same server. Therefore I need to modify the existing connection string and to add the instance name.

I was trying (MSSQLSERVER is the instance name):

"Data Source=localhost\MSSQLSERVER;Initial Catalog=myDb;Integrated Security=True;" providerName="System.Data.SqlClient" 

AND:

"Server=localhost/MSSQLSERVER;Database=myDb;User Id=user; Password=password;" providerName="System.Data.SqlClient"

AND more but could not make it work.

The error I am getting is:

The network name cannot be found

4
  • try: connectionString="Data Source=localhost\v11.0 or maybe Server=localhost\MSSQLLocalDB .. got this from here: msdn.microsoft.com/en-us/library/hh510202.aspx Commented Jan 5, 2017 at 9:06
  • What are you connecting from? Commented Jan 5, 2017 at 9:21
  • 1
    From the same server Commented Jan 5, 2017 at 9:25
  • try to set port (1433 - default value) in the connection string, following example works for me: "Data Source=localhost\MSSQLSERVER,1433;Initial Catalog=master;Integrated Security=True;Persist Security Info=True;MultipleActiveResultSets=True" Commented Aug 26, 2020 at 14:23

1 Answer 1

10

If you have SQL Server 2014 as your default instance (with no instance name needed to connect to it - that's the MSSQLSERVER "instance", but that name must not be used in the connection string!), then you must use a separate, different instance name for your SQL Server 2016 installation, e.g. SQL2016.

In that case, your connection string will need to use .\SQL2016 or (local)\SQL2016 or localhost\SQL2016 as the server/instance name (defined by the server= or data source= settings in the connection string).

So your connection string for SQL Server 2016 should be something like:

Data Source=localhost\SQL2016;Initial Catalog=myDb;Integrated Security=True;

You can go to the SQL Server Configuration Manager to see what services are defined and thus what instances are present on your machine:

enter image description here

Look for the SQL Server services - the value in parenthesis is the instance name (where MSSQLSERVER stands for the default instance that doesn't need to be specified as such - just the machine name is enough for connecting to the default instance)

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

2 Comments

If I understand, After the SQL server 2016 installation I can leave the connection string to the 'SQL server 2014' without the instance name as it the default instance while the connection strings to the Sql 2016 will have to use the new instance name... is it correct ?
@Eyal: yes - if you want to have SQL Server 2014 and 2016 side-by-side, then leave the 2014 installation as default instance be as it is - and install SQL Server 2016 with a separate specific instance name and use that instance name in your connection string

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.