SQL Server连接字符串-点(“。”)或“(本地)”或“(localdb)”

时间:2022-11-06 15:53:15

I've recently had to install SQL Server and restore a database to 2 laptops, the first took me a couple of days to figure out, the second I'm still struggling on.

我最近不得不安装SQL Server并将一个数据库恢复到2台笔记本电脑上,第一次我花了几天时间才弄明白,第二次我还在苦苦挣扎。

On both I was getting this error here:

在这两个方面我都犯了这个错误:

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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

在建立到SQL Server的连接时发生与网络相关或特定于实例的错误。没有找到或无法访问服务器。验证实例名是否正确,并将SQL Server配置为允许远程连接。(提供者:命名管道提供程序,错误:40 -无法打开到SQL服务器的连接)

I'm still getting it on the second.

我还在第二个上。

I did a lot of research and followed all the steps listed on * and other sites such as ensuring SQL Server has TCP and Named Pipes running, ensuring that SQL Server was allowing remote connections, and all other troubleshooting steps I could find.

我做了很多研究,并遵循了*和其他站点上列出的所有步骤,比如确保SQL Server有TCP和命名管道运行,确保SQL Server允许远程连接,以及我能找到的所有其他故障排除步骤。

In the end I discovered that I was just entering the connection string wrong on the first laptop. I was trying to use (localdb)\MSSQLSERVER2012 (or something like that) as it says to do on so many sites. It started working when I used .\MSSQLSERVER2012. I thought they would all point to the same place but obviously not.

最后我发现我只是在第一个笔记本电脑上输入了错误的连接字符串。我试着使用(localdb)\MSSQLSERVER2012(或者类似的东西),因为它说要在这么多的网站上运行。当我使用时,它开始工作了。我以为他们会指向同一个地方,但显然不是。

I really want to avoid this problem again, and figure out how to get my second laptop set up. How do I know if I should be using .\SQLSERVER2012, (local)\SQLSERVER2012, (localdb)\SQLSERVER2012, etc? Is there a simple way of finding this out using a command line tool like SqlLocalDb? And how is this set up in the first place?

我真的想再次避免这个问题,并想办法让我的第二个笔记本电脑安装起来。如何知道是否应该使用。\SQLSERVER2012、(本地)\SQLSERVER2012、(localdb)\SQLSERVER2012等?是否有一种简单的方法可以使用SqlLocalDb这样的命令行工具来找到这个结果?这是怎么建立的呢?

1 个解决方案

#1


42  

. and (local) and YourMachineName are all equivalent, referring to your own machine.

。(本地)和你的机器名都是等价的,指的是你自己的机器。

(LocalDB)\instance is SQL Server 2012 Express only.

(LocalDB)\实例是SQL Server 2012 Express only。

The other parts are depending on how you install - if you install with an instance name - then you need to spell that instance name out (SQL Server Express by default uses the SQLEXPRESS instance name, while other editions of SQL Server will try to use the default instance without any special name).

其他部分是取决于你如何安装——如果你安装一个实例名,然后你需要拼写,实例名(默认SQL Server Express使用SQLEXPRESS实例名称,而其他版本的SQL Server将使用默认的实例没有任何特别的名字)。

So for a "normal" SQL Server installed with all default options on your local machine, use

因此,对于安装了本地机器上所有默认选项的“普通”SQL服务器,请使用

.    or   (local)     or          YourMachineName

For SQL Server Express installed with all the default settings, use

对于安装了所有默认设置的SQL Server Express,请使用

.\SQLEXPRESS    or   (local)\SQLEXPRESS     or          YourMachineName\SQLEXPRESS

If you look at the SQL Server Configuration Manager (launch it from the start menu), you'll see:

如果查看SQL Server配置管理器(从开始菜单启动它),您将看到:

SQL Server连接字符串-点(“。”)或“(本地)”或“(localdb)”

If the SQL Server entry reads (MSSQLSERVER) then that's that default instance (without any name) - otherwise you'd see the instance name in brackets

如果SQL Server条目读取(MSSQLSERVER),那么这就是默认实例(没有任何名称)——否则您将在括号中看到实例名。

#1


42  

. and (local) and YourMachineName are all equivalent, referring to your own machine.

。(本地)和你的机器名都是等价的,指的是你自己的机器。

(LocalDB)\instance is SQL Server 2012 Express only.

(LocalDB)\实例是SQL Server 2012 Express only。

The other parts are depending on how you install - if you install with an instance name - then you need to spell that instance name out (SQL Server Express by default uses the SQLEXPRESS instance name, while other editions of SQL Server will try to use the default instance without any special name).

其他部分是取决于你如何安装——如果你安装一个实例名,然后你需要拼写,实例名(默认SQL Server Express使用SQLEXPRESS实例名称,而其他版本的SQL Server将使用默认的实例没有任何特别的名字)。

So for a "normal" SQL Server installed with all default options on your local machine, use

因此,对于安装了本地机器上所有默认选项的“普通”SQL服务器,请使用

.    or   (local)     or          YourMachineName

For SQL Server Express installed with all the default settings, use

对于安装了所有默认设置的SQL Server Express,请使用

.\SQLEXPRESS    or   (local)\SQLEXPRESS     or          YourMachineName\SQLEXPRESS

If you look at the SQL Server Configuration Manager (launch it from the start menu), you'll see:

如果查看SQL Server配置管理器(从开始菜单启动它),您将看到:

SQL Server连接字符串-点(“。”)或“(本地)”或“(localdb)”

If the SQL Server entry reads (MSSQLSERVER) then that's that default instance (without any name) - otherwise you'd see the instance name in brackets

如果SQL Server条目读取(MSSQLSERVER),那么这就是默认实例(没有任何名称)——否则您将在括号中看到实例名。