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

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

问题描述

我最近不得不安装 SQL Server 并将数据库恢复到 2 台笔记本电脑,第一次我花了几天时间才弄明白,第二次我仍在努力.

在这两种情况下,我都在这里收到此错误:

<块引用>

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

我还在第二个.

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

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

我真的很想再次避免这个问题,并弄清楚如何设置我的第二台笔记本电脑.我怎么知道我是否应该使用 .SQLSERVER2012(local)SQLSERVER2012(localdb)SQLSERVER2012 等?有没有一种简单的方法可以使用像 SqlLocalDb 这样的命令行工具来解决这个问题?这首先是如何设置的?

解决方案

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

(LocalDB)instance 仅适用于 SQL Server 2012 Express.

其他部分取决于您的安装方式 - 如果您使用实例名称进行安装 - 那么您需要拼出该实例名称(默认情况下为 SQL Server Express使用 SQLEXPRESS 实例名称,而其他版本的 SQL Server 将尝试使用没有任何特殊名称的默认实例).

因此,对于在本地计算机上安装了所有默认选项的普通"SQL Server,请使用

<预><代码>.或(本地)或 YourMachineName

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

.SQLEXPRESS or (local)SQLEXPRESS or YourMachineNameSQLEXPRESS

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

如果 SQL Server 条目读取的是 (MSSQLSERVER) 那么那就是默认实例(没有任何名称) - 否则你会在括号中看到实例名称

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:

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)

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.

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.

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?

解决方案

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

(LocalDB)instance is 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).

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

.    or   (local)     or          YourMachineName

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

.SQLEXPRESS    or   (local)SQLEXPRESS     or          YourMachineNameSQLEXPRESS

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

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天全站免登陆