SQL Server Express LocalDB 可以远程连接吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9193746/
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
Can SQL Server Express LocalDB be connected to remotely?
提问by Mark Whitfeld
I am looking into using the new SQL Server Express LocalDB (I think it is code named "Denali") for a desktop application.
我正在考虑将新的 SQL Server Express LocalDB(我认为它的代码名为“Denali”)用于桌面应用程序。
It is currently running with SQL Compact, but the user is wanting to share the database between multiple PCs on a network. Unfortunately this is not something that SQL Compact can do, so I am investigating other solutions.
它当前与 SQL Compact 一起运行,但用户希望在网络上的多台 PC 之间共享数据库。不幸的是,这不是 SQL Compact 可以做到的,所以我正在研究其他解决方案。
The client requires the ability to send database files easily to other sites or to back them up to a flash disk, so I am avoiding going to SQL Express because there is quite a bit of "administrator" knowledge required to backup and restore.
客户端需要能够轻松地将数据库文件发送到其他站点或将它们备份到闪存盘,因此我避免使用 SQL Express,因为备份和恢复需要相当多的“管理员”知识。
So, my questions is, does the new SQL Express LocalDB support remote connections to the database over a network and/or through a shared network folder with the mdf file in it?
所以,我的问题是,新的 SQL Express LocalDB 是否支持通过网络和/或通过其中包含 mdf 文件的共享网络文件夹远程连接到数据库?
LocalDB does support supplying a path for an attached local DB in it's connect string (AttachDbFileName) hence the shared network folder option.
LocalDB 确实支持在其连接字符串 (AttachDbFileName) 中为附加的本地数据库提供路径,因此共享网络文件夹选项。
NOTE:This question pertains to "LocalDB" the new version of SQL Express 'Denali' and not to SQL Server Express 2008 or prior. See article here announcing LocalDB's release: http://blogs.msdn.com/b/sqlexpress/archive/2011/07/12/introducing-localdb-a-better-sql-express.aspx
注意:此问题与 SQL Express 'Denali' 的新版本“LocalDB”有关,与 SQL Server Express 2008 或之前版本无关。请参阅此处宣布 LocalDB 发布的文章:http: //blogs.msdn.com/b/sqlexpress/archive/2011/07/12/introducing-localdb-a-better-sql-express.aspx
采纳答案by Krzysztof Kozielczyk
No, SQL Server Express LocalDBdoesn't accept remote connections.
不,SQL Server Express LocalDB不接受远程连接。
The idea with shared network folder might work, but only if you are able to make sure the LocalDB instance is shutdown before you try to copy the file. Also keep in mind that only one LocalDB instance can have any given database file open at the same time. and don't forget about the log files!
共享网络文件夹的想法可能可行,但前提是您能够确保在尝试复制文件之前关闭 LocalDB 实例。还要记住,只有一个 LocalDB 实例可以同时打开任何给定的数据库文件。并且不要忘记日志文件!
Additional security warning: unlike SQL Server Compact databases, SQL Server Express databases (including LocalDB ones) are not designed as secure data exchange format. For instance, they can contain malicious code in .NET assemblies embedded in them. So you should never open databases from untrusted source.
附加安全警告:与 SQL Server Compact 数据库不同,SQL Server Express 数据库(包括 LocalDB 数据库)并非设计为安全的数据交换格式。例如,它们可以在嵌入其中的 .NET 程序集中包含恶意代码。所以你永远不应该从不受信任的来源打开数据库。
Maybe providing the customer with a simple tool that automates the backup process would be a better idea?
也许为客户提供一个自动备份过程的简单工具会是一个更好的主意?
回答by Zoltan
This isn't a fresh thread, but I would like to share my experience with SQL Server Express database LocalDB.
这不是一个新鲜话题,但我想分享我使用 SQL Server Express 数据库 LocalDB 的经验。
I have a WPF C# project using SQL database with LocalDb Engine. It is working fine no problem, I can access the database. I wanted this program to work on network with more PCs. In my scenario on the network another PC can use the database from my PC (using UNC path in the connection string).
It seemed to me the remote connection is working. But when the remote PC is connected, I could not connect to my database. If I connected first the remote PC could not connect. So this tells me that the remote connection is working, but the multiple connection is not allowed.
OK, I didn't give up and I run the program from my PC twice and I saw it is working which tells me that the same SQL LocalDB engine can connect several times.
我有一个使用带有 LocalDb 引擎的 SQL 数据库的 WPF C# 项目。它工作正常没问题,我可以访问数据库。我希望这个程序能够在更多 PC 的网络上运行。在我的网络场景中,另一台 PC 可以使用我 PC 中的数据库(在连接字符串中使用 UNC 路径)。
在我看来远程连接正在工作。但是当连接远程 PC 时,我无法连接到我的数据库。如果我先连接远程 PC 无法连接。所以这告诉我远程连接正在工作,但不允许多连接。
好吧,我没有放弃,我从我的 PC 上运行了两次程序,我看到它正在工作,这告诉我同一个 SQL LocalDB 引擎可以连接多次。
I hope this experience will help someone. Thanks.
我希望这次经历会对某人有所帮助。谢谢。
回答by Neil Knight
In short, yes it can. Here is a tutorialon how to configure it.
简而言之,是的,它可以。这是有关如何配置它的教程。
Also, here is another postwith a potential issue that might occur.
Both explain how to configure SQL Server Express to accept Remote Connections.
两者都解释了如何配置 SQL Server Express 以接受远程连接。