如何向网络上的服务器提供连接字符串?
我使用的是 SQLite,所以它只是一个文件,而不是服务器,但计划如下:
在一台计算机上安装应用程序 + 物理 .sqlite 文件,并通过网络安装在另一台计算机上,让其他用户连接到 .sqlite 文件。
因此,我必须共享该文件夹并授予其权限,以允许每个人都可以从中读取和写入。
这是我的 App.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="ColegioMentorEntities" connectionString="metadata=res://*/Repositories.ColegioMentor.csdl|res://*/Repositories.ColegioMentor.ssdl|res://*/Repositories.ColegioMentor.msl;provider=System.Data.SQLite;provider connection string="data source=C:\Users\Sergio\Desktop\ColegioMentor.sqlite"" providerName="System.Data.EntityClient" /></connectionStrings>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
</startup>
</configuration>
看来我可以更改连接字符串!伟大的!但是如何在字符串中引用网络位置呢?
I'm using SQLite so it's only a file, not a server, but here's the plan:
Install the application + the physical .sqlite file on a machine and on another machine over the network, let the other user connect to the .sqlite file.
So I'd have to share that folder and give it permissions to allow everyone to read and write from it.
Here's my App.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="ColegioMentorEntities" connectionString="metadata=res://*/Repositories.ColegioMentor.csdl|res://*/Repositories.ColegioMentor.ssdl|res://*/Repositories.ColegioMentor.msl;provider=System.Data.SQLite;provider connection string="data source=C:\Users\Sergio\Desktop\ColegioMentor.sqlite"" providerName="System.Data.EntityClient" /></connectionStrings>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
</startup>
</configuration>
It seems I CAN change the connection string! Great! But how do I reference a networked location in a string?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如此处所建议的,如果您需要支持,您可能需要考虑使用 MySQL 之类的东西超过单个用户,因为并发访问 SQLite 时可能会出现潜在的损坏问题。
尽管 SQLite 确实支持并发访问,但您可以在其常见问题解答(参见第 5 项和第 6 项)。
从该页面:
As suggested here, you may want to consider using something like MySQL if you need to support more than a single user, due to potential corruption issues that can arise when you access SQLite concurrently.
Though SQLite does support concurrent access, there are several caveats that you can read about on their FAQ (see items 5 and 6).
From that page:
首先想到的是标准 UNC 路径,例如:
我希望这有帮助!
The first thing that comes to mind is a standard UNC path, like:
I hope this helps!
要回答有关 ShareName 的问题,它将是共享文件夹的共享名称,如属性对话框 > 中所示。共享选项卡>共享名称,而不是 Windows 资源管理器文件夹名称(假设您使用的是 Windows)。
To answer your question about the ShareName, it would be the shared name of the shared folder, as shown in the properties dialog > Shared Tab > share name, not the windows explorer folder name (assuming you're using windows).