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

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

问题描述

我最近不得不安装 SQL Server 并将数据库恢复到两台笔记本电脑,第一台花了我几天时间才弄清楚,第二台我还在苦苦挣扎.

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 是否配置为允许远程连接.(提供者:命名管道提供者,错误: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)

我仍然在第二个得到它.

I'm still getting it on the second.

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

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 等?有没有一种简单的方法可以使用像 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?

推荐答案

.(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          YourMachineNameSQLEXPRESS

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

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