SQL Server连接字符串 - 点(“。”)或“(本地)”。或“(localdb)”。 [英] SQL Server Connection Strings - dot(".") or "(local)" or "(localdb)"

查看:406
本文介绍了SQL Server连接字符串 - 点(“。”)或“(本地)”。或“(localdb)”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近不得不安装SQL Server并将数据库还原到2台笔记本电脑,第一次花了我几天时间才找到,第二次我还在努力。

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.

我在这里收到这个错误:

On both I was getting this error here:


建立网络相关或实例特定的错误连接到SQL Server。找不到服务器或无法访问。验证实例名称是否正确并且SQL Server配置为允许远程连接。 (提供程序:Named Pipes Provider,错误:40 - 无法打开到SQL Server的连接)

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)

第二个。

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

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.

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

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.

我真的想避免这个问题,并找出如何让我的第二台笔记本电脑设置。我如何知道我是否应该使用 .\SQLSERVER2012 (local)\SQLSERVER2012 (localdb)\SQLSERVER2012 ,etc?有一个简单的方法找到这个使用命令行工具,如 SqlLocalDb ?这是如何设置在第一位?

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?

UPDATE
现在我的网站在我的第二台笔记本电脑上通过将其更改为(localdb)\mssqlserver2012,但我的服务是使用相同的连接字符串会收到相同的错误消息。

UPDATE I've now got the site working on my second laptop by changing it to "(localdb)\mssqlserver2012, but my service which is using the same connection string is getting the same error message.

推荐答案

(local) YourMachineName 都是等价的,指的是您自己的机器。

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

(LocalDB)\instance 只是SQL Server 2012 Express

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

其他部分取决于你如何安装 - 如果你安装一个实例名称,那么你需要拼写该实例名称(SQL Server Express 默认情况下使用 SQLEXPRESS 实例名称,而其他版本的SQL Server将尝试使用没有任何特殊名称的默认实例)。

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,请使用

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

.    or   (local)     or          YourMachineName

对于SQL Server Express 设置,使用

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

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

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

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

如果 SQL Server 条目读取(MSSQLSERVER),那么那是默认实例 - 否则您会在括号中看到实例名称

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连接字符串 - 点(“。”)或“(本地)”。或“(localdb)”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆