-1

I have several SQL servers in my system:

2017 MSSQLSERVER
2008 SQLEXPRESS

In SSMS I see them like:

GM\
GM\SQLEXPRESS

enter image description here

If I need to connect to SQLEXPRESS I use connection string with . in Server:

connectionString="Server=.;Database=LearnCSharp;Integrated Security=True"

But what does . means in my case and what should be placed in connection string in order to connect to 2017 MSSQLSERVER?

UPD.:

. connects to 2017 server. I have noticed that before computer restart it was connecting to 2008 server

GM connects to 2017 server.

.\MSSQLSERVER generates exception in my application;

System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 25 - Connection string is not valid) ---> System.ComponentModel.Win32Exception (0x80004005): The parameter is incorrect

.\SQLEXPRESS and GM\SQLEXPRESS - both connects to server 2008

vico
  • 17,051
  • 45
  • 159
  • 315
  • . means local. fo your case why not just use raw connectionstring? `cconnectionString="Server=yourcomputername/sql2008express;Database=LearnCSharp;Integrated Security=True"`
    `connectionString="Server=yourcomputername/sql2017express;Database=LearnCSharp;Integrated Security=True"`
    – MVC newbie Nov 14 '17 at 07:24
  • 1
    I'm voting to close this question as off-topic because the original question has been answered, and this question has since been edited to ask about new, unrelated problems. It is not intended that an initial question is edited throughout the entire development life of a system, to ask about every problem that occurs throughout that development life. Please ask a new question – Caius Jard Nov 14 '17 at 07:55
  • @vico you refer to a primary SQL Server instance (MSSQLSERVER) by the machine's name or address. You only need to use `name\instance` for additional named instances. `.`, `(local)` and `localhost` are all shortcuts for the local machine using different networking protocols. Use `.` to connect to the local primary instance, `.\SQLEXPRESS` or `.\MyInstance` etc to connect to named instances. – Panagiotis Kanavos Nov 14 '17 at 08:58

2 Answers2

0

It means localhost or "this machine"

To specify an instance name, use a backslash after the dot (or computer name):

.\SQLEXPRESS
YOURCOMPUTER\SQLEXPRESS
OTHERCOMPUTER\SQLEXPRESS

etc

Remember when this app is deployed to another machine, the value of "this machine" changes. This may or may not be what you want, so watch for it in future

It's also worth noting that the default SQL Server instance cannot be referenced by name, and if you try to give its name the connection won't work out. If you know you want to connect to the default SQL Server instance (whichever one that is, and there can be only one) then don't put a slash or a name, just a reference to the machine:

.

YOURCOMPUTER

etc

Caius Jard
  • 72,509
  • 5
  • 49
  • 80
  • In .\MSSQLSERVER case I got error `A network-related or instance-specific error occurred while establishing a connection to SQL Server` I have updated question body with more details – vico Nov 14 '17 at 07:45
  • maybe that instance is not configured to accept tcp connections n the sql server surface area configuration tool, maybe it's firewalled, maybe it runs a different port.. whatever it is it is beyond the scope of this question. please accept an answer (because the question you asked has been answered) and ask a new question – Caius Jard Nov 14 '17 at 07:51
  • @vico you *don't* need to specify any name for the primary instance. Just use `.` or `localhost` or `(local)` – Panagiotis Kanavos Nov 14 '17 at 08:52
  • @CaiusJard please fix `.\MSSQLSERVER`. You don't need (or can) specify a name for the primary instance – Panagiotis Kanavos Nov 14 '17 at 08:53
  • That's not what the question was about, and even in the question text he complains that restarting his computer and the default instance changed.. But I'll update my answer with your helpful note that the default instance cannot be connected to by specifying its name.. – Caius Jard Nov 14 '17 at 10:04
0

The dot is simply an abbreviated way of referencing your local machine and as highlighted in the following ".\MSSQLSERVER" should do it: SQL Server Connection Strings - dot(".") or "(local)" or "(localdb)").

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
Kevin Bluer
  • 235
  • 4
  • 8
  • In .\MSSQLSERVER case I got error `A network-related or instance-specific error occurred while establishing a connection to SQL Server` I have updated question body with more details – vico Nov 14 '17 at 07:45
  • You don't need to specify a name for the primary instance. `.` works, `.\MSSQLSERVER` doesn't – Panagiotis Kanavos Nov 14 '17 at 08:54
  • Furthermore, *don't* post an answer that only links to a duplicate question. Vote to close as duplicate. Otherwise this is only adding noise and making it *harder* for the next person with the same problem to find a solution – Panagiotis Kanavos Nov 14 '17 at 09:00