无法使用 SQL Server CE 数据库.file 部署应用程序
我正在尝试使用 SQL Server database.sdf
文件部署一个简单的 Windows 桌面应用程序。我已经按照本演练中的步骤操作了大约 10 次,但仍然遇到问题。 http://msdn.microsoft.com/en-us/library/bb546200.aspx
在我的 app.config
文件中,我的连接字符串是这样的:
<add name="VendorTracker_2._0.Properties.Settings.Database1ConnectionString"
connectionString="Data Source=C:\Users\Eamon\Documents\Visual Studio 2008\Projects\VendorTracker 2.0\VendorTracker 2.0\Database1.sdf"
providerName="Microsoft.SqlServerCe.Client.3.5" />
根据演练,Windows 安装程序应该识别出我正在使用 SQL Server CE .sdf
文件并创建一个新的连接字符串:
<add name="VendorTracker_2._0.Properties.Settings.Database1ConnectionString1"
connectionString="Data Source=|DataDirectory|\Database1.sdf"
providerName="Microsoft.SqlServerCe.Client.3.5" />
它确实将此连接字符串添加到 app.config
文件中。现在,我在 app.config
文件中列出了两个连接字符串。当我将应用程序部署到我的开发计算机上时,它工作正常,连接到 .sdf
文件没有问题。
但是,当我将安装文件夹及其内部所有内容复制到另一台“测试”计算机时,当我尝试运行该应用程序时,出现以下错误:
路径无效。检查数据库的目录。 [路径=C:\Users\MyName\Documents\Visual Studio 2008\Projects\VendorTracker 2.0 Database1.sdf]。
该应用程序继续运行,但没有数据,并且不允许我将任何内容保存到数据库中。
为什么 .sdf
文件没有
Data Source=|DataDirectory|\Database1.sdf
像预期的那样使用连接字符串进行部署?让我发疯。我已经尝试了一切。有人成功地将 SQL Server CE .sdf
文件与独立的 Windows 桌面应用程序一起使用吗?我知道它们经常用于移动设备,但这应该没有什么区别。请帮忙。
海洋列车
I am trying to deploy a simple windows desktop app using a SQL Server database.sdf
file. I have followed the steps in this walkthrough about 10 times and I still am having problems. http://msdn.microsoft.com/en-us/library/bb546200.aspx
In my app.config
file my connection string is this:
<add name="VendorTracker_2._0.Properties.Settings.Database1ConnectionString"
connectionString="Data Source=C:\Users\Eamon\Documents\Visual Studio 2008\Projects\VendorTracker 2.0\VendorTracker 2.0\Database1.sdf"
providerName="Microsoft.SqlServerCe.Client.3.5" />
According to the walkthrough, the windows installer should recognize that I am using a SQL Server CE .sdf
file and create a new connection string:
<add name="VendorTracker_2._0.Properties.Settings.Database1ConnectionString1"
connectionString="Data Source=|DataDirectory|\Database1.sdf"
providerName="Microsoft.SqlServerCe.Client.3.5" />
It does add this connection string to the app.config
file. Now I have both connection strings listed in the app.config
file. When I deploy the app onto my development computer, it works fine, no problem connecting to the .sdf
file.
But when I copy the install folder and everything inside of it to a different "testing" computer I get the following error when I try to run the app:
The path is not valid. Check the directory for the database. [ Path=C:\Users\MyName\Documents\Visual Studio 2008\Projects\VendorTracker 2.0 Database1.sdf].
The app continues to run but there is no data and It will not allow me to save anything to the database.
Why doesn't the .sdf
file get deployed with the connection string:
Data Source=|DataDirectory|\Database1.sdf
like it is suppose to? Driving me nuts. I have tried everything. Has anyone successfully used a SQL Server CE .sdf
file with a stand alone windows desktop app? I know they are used a lot for mobile devices but that shouldn't make a difference. Please help.
Oceantrain
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须手动更改连接字符串。另外,请仔细考虑放置文件的位置,因为并非所有位置都是可写的
You must change the connection string manually. Also, consider carefully where you place the file, as not all places are writable