简体   繁体   English

HeidiSql连接到MS SQL Server LocalDB

[英]HeidiSql connection to MS SQL Server LocalDB

I have been trying in vain to connect to my SQL Server database, attached to the LocalDB instance (localdb)\\v11.0 , using HeidiSql and Windows Authentication. 我一直试图连接到我的SQL Server数据库,使用HeidiSql和Windows身份验证连接到LocalDB实例(localdb)\\v11.0

My testing has shown that HeidiSql can connect to the permanently installed MSSQLSERVER and SQLEXPRESS instances as follows: 我的测试表明,HeidiSql可以连接到永久安装的MSSQLSERVERSQLEXPRESS实例,如下所示:

MSSQLSERVER : MSSQLSERVER

  • SQL Server: (named pipe) SQL Server :(命名管道)
  • Hostname / IP: . 主机名/ IP :.
  • Use Windows Authentication 使用Windows身份验证

SQLEXPRESS : SQLEXPRESS

  • SQL Server: (named pipe) SQL Server :(命名管道)
  • Hostname / IP .\\SQLEXPRESS 主机名/ IP。\\ SQLEXPRESS
  • Use Windows Authentication 使用Windows身份验证

The LocalDB connection proves elusive. LocalDB连接证明是难以捉摸的。

My reading of the situation suggests that the LocalDB instance is something of a phantom created by Visual Studio and SQL Server Management Studio as and when required. 我对这种情况的解读表明,LocalDB实例是Visual Studio和SQL Server Management Studio在需要时创建的一个幻像。 They don't persist or exist when these programs aren't running. 当这些程序没有运行时,它们不会持久存在。 When they are running access is buried in these programs and not available to other applications. 当它们运行时,访问被隐藏在这些程序中,而不能用于其他应用程序。

I know I can switch to MSSQLSERVER or SQLEXPRESS as the standard database server for my Visual Studio applications but am interested to know whether there is a pathway for connecting to HeidiSql the LocalDB instance. 我知道我可以切换到MSSQLSERVERSQLEXPRESS作为我的Visual Studio应用程序的标准数据库服务器,但我很想知道是否有一个连接HeidiSql的路径是LocalDB实例。

It can work, but is tricky. 它可以工作,但很棘手。 You need to use the LocalDB named pipe as the Heidi hostname. 您需要使用LocalDB命名管道作为Heidi主机名。 Using LocalDB V12 for example: 以LocalDB V12为例:

sqllocaldb info
sqllocaldb start MSSQLLocalDB
sqllocaldb info MSSQLLocalDB

The "info" parameter reveals: “info”参数显示:

\\.\pipe\LOCALDB#12345678\tsql\query

Note the number is a random hash, which complicates things, as you need to keep checking it. 请注意,该数字是随机哈希,这使得事情变得复杂,因为您需要继续检查它。 It's possible to batch/script the above, with Heidi's command line options . 使用Heidi的命令行选项可以批量/编写上述脚本。

My command line: 我的命令行:

heidisql -d=LocalDB -h=%pipename% -n=3 -d=LocalDB

The -d parameter is used twice intentionally. -d参数有意使用两次。

For normal SQL Server instances rather than LocalDB instances: 对于普通的SQL Server实例而不是LocalDB实例:

I realize this question asks about local db; 我意识到这个问题是关于本地db的; however, this result came up when I was looking around and this answer would have helped me. 然而,当我环顾四周时,这个结果出现了,这个答案对我有帮助。

In windows search (press enter and type to search) enter "sql server configuration manager". 在Windows搜索中(按enter键并键入搜索),输入“sql server configuration manager”。 Open that, but make sure you are not opening "sql server master data servervices configuration manager" that is not correct. 打开它,但请确保您没有打开“sql server master data servervices配置管理器”,这是不正确的。 For me, the first time I had to look be low it in the results under "apps". 对我来说,第一次在“apps”下的结果中我不得不低调。

Then Click "SQL Server Network Configuration". 然后单击“SQL Server网络配置”。

If that does not come up, you can manually open the file. 如果没有出现,您可以手动打开该文件。 See: https://docs.microsoft.com/en-us/sql/relational-databases/sql-server-configuration-manager 请参阅: https//docs.microsoft.com/en-us/sql/relational-databases/sql-server-configuration-manager

For me it is at "C:\\Windows\\SysWOW64\\SQLServerManager13.msc" 对我来说,它位于“C:\\ Windows \\ SysWOW64 \\ SQLServerManager13.msc”

Double click "Protocols for [your instance here]" 双击“[此处的实例]的协议”

To access connect using something besides SSMS, you'll need to choose to enable a named pipe, or TCP/IP. 要使用SSMS之外的其他东西访问连接,您需要选择启用命名管道或TCP / IP。

TCP/IP TCP / IP

Right Click "TCP/IP" and click properties 右键单击“TCP / IP”,然后单击属性

Change "Enabled" to true 将“已启用”更改为true

Change IP4 (or the one with 127.0.0.1 as the IP Address) to be enabled. 更改要启用的IP4(或具有127.0.0.1作为IP地址的IP4)。

Click "Ok". 单击“确定”。

Jump to restarting 跳转到重新启动

Named Pipe 命名管道

Right click "Named Pipes" and click "Properties" 右键单击“命名管道”,然后单击“属性”

Change "Enabled" to true 将“已启用”更改为true

Copy the "Pipe Name" and use that in your database client later 复制“管道名称”,稍后在数据库客户端中使用它

Jump to restarting 跳转到重新启动

Restarting 重新启动

As you are warned, you need to restart the service, so click "SQL Server Services" on the left 在收到警告时,您需要重新启动该服务,因此请单击左侧的“SQL Server服务”

Right click "SQL Server ([your instance name])" and click "Restart" 右键单击“SQL Server([您的实例名称])”并单击“重新启动”

You can now use your database client to browse your sql server instance. 您现在可以使用数据库客户端浏览sql server实例。 In heidi, you simply select the network type that matches your setup - choose "Use Windows authentication" and fill in the appripriate hostname/ip (the pipe name or the ip depending on which method you chose to use) 在heidi中,您只需选择与您的设置匹配的网络类型 - 选择“使用Windows身份验证”并填写appripriate hostname / ip(管道名称或ip,具体取决于您选择使用的方法)

FYI, I answered this question in another SO question as well with step-by-step instructions. 仅供参考,我在另一个SO问题中回答了这个问题以及逐步说明。 Special thanks to @GravityWell for the pipe name suggestion ! 特别感谢@GravityWell管道名称建议

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM