使用带有SQL Server 2008数据库的clickonce部署Windows应用程序 [英] Deploying windows application using clickonce with SQL server 2008 database

查看:119
本文介绍了使用带有SQL Server 2008数据库的clickonce部署Windows应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows应用程序,我想创建一个点击一次应用程序。当我在客户端计算机上部署文件时,从visual studio创建clickonce应用程序时,它在尝试访问数据库时抛出错误。我已在clickonce中包含数据库文件app。数据库文件存储在客户端PC上的位置:

C:\ Users \Admin \ AppData \ Local \ Apps \\\\\\\\\\\\\\\\\\\\\ .329 \ P54O9PWP.VCY \ nain..tion_b5deb07cfd237918_0001.0000_ce0d12c892dd7f73 \ data \Database1.mdf



我应该提到什么连接字符串我的项目,当代码发布时,它应该访问数据库存储在客户端机器上的位置。

当前的连接字符串是:



当我从visual studio运行代码但是不能在客户端工作时,这个连接字符串工作正常。



我尝试过:



试图改变连接strin g但无效。如果保持相同的连接字符串抛出错误'与Sql Server建立连接错误时出现网络相关或实例特定错误-40无法打开与Sql Server的连接'

解决方案

这不是SQL Server的工作方式。您不会将 .mdf 文件复制到客户端计算机;您将它附加到现有的SQL Server实例,并让客户端连接到该实例。



如果您使用 AttachDBFileName 选项,用户需要在其计算机上安装SQL Server Express的副本。您还会发现数据库将在应用程序的不同实例之间或不同用户或不同计算机之间共享。



< a href =https://blogs.sqlsentry.com/aaronbertrand/bad-habits-attachdbfilename/>坏习惯:使用AttachDBFileName - SQL SentrySQL Sentry团队博客 [ ^ ]



另请注意此功能将在以后的版本中删除:



此功能将在Microsoft SQL Server的未来版本中删除。避免在新的开发工作中使用此功能,并计划修改当前使用此功能的应用程序。





如果你想要一个简单的基于文件的数据库,你可以使用 LocalDB [ ^ ],但仍需要安装。或者,您可以使用SQL CE,但功能要少得多。



SQL Express v LocalDB v SQL Compact Edition - Jerry Nixon [ ^ ]


I have a windows application and I want to create a click once app.After creating clickonce app from visual studio when I deploy the file on client machine it throws error when trying to access database.I have included database file within the clickonce app.The database file is stored on client pc on location :
C:\Users\Admin\AppData\Local\Apps\2.0\Data\8Z14E1HB.329\P54O9PWP.VCY\ nain..tion_b5deb07cfd237918_0001.0000_ce0d12c892dd7f73\Data\Database1.mdf

What connection string should I mentioned in my project that when code is published it should access the location the database is stored on client machine.
The current connectionstring is :

This connectionstring works fine when I run the code from visual studio but wont work on client side.

What I have tried:

Tried to change connection string but to no avail.If keep same connectionstring throws error 'A network related or instance specific error while establishing connection to Sql Server error-40 Could not open connection to Sql Server '

解决方案

That's not how SQL Server works. You don't copy the .mdf file to the client computer; you attach it to an existing instance of SQL Server, and have the client connect to that instance.

If you're using the AttachDBFileName option, the user will need to have a copy of SQL Server Express installed on their computer. You will also find that the database will not be shared between different instances of your application, or between different users or different computers.

Bad habits : Using AttachDBFileName - SQL SentrySQL Sentry Team Blog[^]

Also note that this feature will be removed in a future version:


This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature.



If you want a simple file-based database, you could use LocalDB[^], but that still needs to be installed. Alternatively, you could use SQL CE, but that has far fewer features.

SQL Express v LocalDB v SQL Compact Edition – Jerry Nixon[^]


这篇关于使用带有SQL Server 2008数据库的clickonce部署Windows应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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