Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server 2014 connection string with instance name

Tags:

sql-server

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

like image 616
Eyal Avatar asked Jan 05 '17 09:01

Eyal


People also ask

WHAT IS instance name in SQL Server connection string?

"Data Source=ServerName\InstanceName" specifies that the connection is being established to the named instance InstanceName on the server whose name is ServerName. The LocalDB Named Instance connection string is expressed as follows.

How do I find the database connection string in SQL Server 2014?

Right-click on your connection and select "Properties". You will get the Properties window for your connection. Find the "Connection String" property and select the "connection string". So now your connection string is in your hands; you can use it anywhere you want.

How do I ping SQL Server named instance?

On the Start menu, select Run. In the Run window, type cmd and select OK. In the Command Prompt window, type ping and the IP address of the computer that's running SQL Server.

What are the connection strings in SQL Server 2014?

SQL Server 2014 connection strings. .NET Framework Data Provider for SQL Server. Standard Security Server=myServerAddress;Database=myDataBase;User Id=myUsername; Connection to a SQL Server instance The server/instance name syntax used in the server option is the same for all SQL Server connection strings.

How do I create a connection to a SQL Server instance?

SqlConnectionConnection to a SQL Server instance. The server/instance name syntax used in the server option is the same for all SQL Server connection strings. Server=myServerNamemyInstanceName;Database=myDataBase;User Id=myUsername; Password=myPassword;

Why can I connect to one SQL Server instance but not another?

That should answer an issue where you can connect to one instance, but not another if one instance is running but the other is not. If you did not create a SQL instance during installation, then the default SQL instance will always be MSSQLSERVER, and you will not need to define this in the Server Name spot of the SSMS.

How to connect to SQL Server 2014 from SQL Server 2016?

1 Answer 1. 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.


1 Answers

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)

like image 51
marc_s Avatar answered Nov 03 '22 02:11

marc_s