database SQL Server 连接字符串 - dot(".") 或 "(local)" 或 "(localdb)"
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20217518/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQL Server Connection Strings - dot(".") or "(local)" or "(localdb)"
提问by Owen
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 Server 的连接)
I'm still getting it on the second.
我仍然在第二次得到它。
I did a lot of research and followed all the steps listed on StackOverflow 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.
我做了大量研究,并遵循 StackOverflow 和其他站点上列出的所有步骤,例如确保 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在很多网站上使用(或类似的东西)。当我使用.\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,(local)\SQLSERVER2012,(localdb)\SQLSERVER2012等?有没有一种简单的方法可以使用像这样的命令行工具来找出这个问题SqlLocalDb?这首先是如何设置的?
回答by marc_s
.and (local)and YourMachineNameare all equivalent, referring to your own machine.
.and(local)和YourMachineName都是等价的,指的是你自己的机器。
(LocalDB)\instanceis SQL Server 2012 Expressonly.
(LocalDB)\instance仅适用于 SQL Server 2012 Express。
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 Expressby default uses the SQLEXPRESSinstance 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 Server,请使用
. or (local) or YourMachineName
For SQL Server Expressinstalled 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 配置管理器(从开始菜单启动它),您将看到:


If the SQL Serverentry reads (MSSQLSERVER)then that's that default instance (without any name) - otherwise you'd see the instance name in brackets
如果SQL Server条目读取,(MSSQLSERVER)则这是该默认实例(没有任何名称) - 否则您会在括号中看到实例名称

