如何与数据库一起部署Windows窗体应用程序? [英] How to deploy a windows forms application along with database?

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

问题描述

我在visual studio 10中创建了一个Windows应用程序。我已经创建了它的安装文件。但是我想在另一台PC上使用该软件...所以有没有办法将数据库与软件一起附加。

I have created a windows application in visual studio 10.I have made a setup file of it..But i want to use that software on another pc...so is there any way to attach database along with the software.

推荐答案

首先,您不应在安装中包含SQL Server。有几个原因:

0)您只能出于版权原因分发SQL Server Express - 而不是SQL Server完整版。

1)他们可能已经拥有SQL Server安装在网络上。如果是这样,那么他们可能会想要使用该版本。

2)如果他们确实安装了SQL服务器并且你开始扩散SQL服务器Express实例,那么你将会惹恼数据库管理员...

3)SQl Server的单站点安装比用户控制下的一些分散版本更有可能被备份。

4)对于普通用户来说,安装和管理Sql服务器非常复杂 - 这不是一个好主意!

5)它将破坏使用Sql Server而不是SqlCE或SQLite的主要优势 - 多用户访问。如果每个人都安装了自己的SQL服务器副本,那么您将拥有数据库的多个副本,每个副本由一个人使用。这会引起一些混乱,并且(取决于你如何编写原始数据库)在实现问题时可能需要付出相当大的努力才能组合成单个实例。



因此,除非您需要多用户访问,否则您根本不想使用SQL - 将代码更改为使用SQLCE或SqLite甚至是Access。



如果您确实需要多用户,然后使用应用程序传输数据库的最简单方法是连接到安装程序中的SQL,并检查数据库是否存在 - 如果存在,那么您不想做任何事情。

如果没有,那么让SQL创建它 - 创建一个SQL命令来生成表结构非常容易:

1)打开SQL Management Studio,然后右键单击你的数据库。

2)在任务下,选择生成脚本...在随后出现的对话框中,按下一步直到找到要求保存位置的部分。

3)选择合理的地方,然后单击高级按钮。查找脚本数据类型选项(它应位于常规类别的底部)。选择架构和数据。

4)按确定和下一步直到文件生成。



如果你查看该文件,它将是一个完整的脚本,用于重新生成数据库,包含数据。
Firstly, you should not include SQL Server in your installation. There are a couple of reasons:
0) You can only distribute SQL Server Express for copyright reasons - not SQL Server full version.
1) They may already have SQL Server installed on the network. If so, then they will presumably want to use that version.
2) If they do have SQL server installed and you start proliferating SQL server Express instances, you are going to annoy the heck out of the database administrator...
3) A single site installation of SQl Server is a lot more likely to be backed up than a number of scattered version under user control.
4) Sql server is quite complex for a "normal" user to install and administer - it is not a good idea!
5) It will destroy the primary advantage of using Sql Server over SqlCE or SQLite - multiuser access. If everyone installs their own copy of SQL server, then you will have multiple copies of your database, each used by a single person. This will cause some confusion, and (depending on how you wrote the original database) may take some considerable effort to combine into a single instance when the problem is realized.

So unless you need multi user access, you don't want to use SQL at all - change your code to use SQLCE or SqLite or even Access instead.

If you do need multiuser, then the easiest way to transfer the database with the app is to connect to SQL in your installer, and check if the DB exists - if it does, then you don't want to do anything.
If it doesn't, then get SQL to create it - it's pretty easy to create an SQL Command to generate the table structure:
1) Open the SQL Management Studio, and right click on your database.
2) Under "Tasks", select "Generate Scripts..." In the dialog that follows, press "Next" until you get to the part asking where to save it.
3) Select somewhere sensible, and click the "Advanced" button. Look for the "Types of data to script" option (it should be at the bottom of the "General" category). Select "Schema and data".
4) Press "OK" and "Next" until the file has been generated.

If you look at the file, it will be a complete script to regenerate your database, complete with data.


For this you have follow some steps. And go through following below.

1.You connection string will not write directly inside your code.
For that you have to write your connection string inside a notepad.
And then read the notepad text by streamreader . get connectionstring from your given notepad.
then pass this connectionstring to connect database.

2. Now you will install some another system. You just put that notepad your specific folder or filepath.

...
Indirectly you need connectionstring in dynamic.

Or you can do also

Make a page. On it's page load it will check that connectionstring file exists on that fixed location or not.
If file not exists then it will ask to enter ConnectionString on the start of application.
If file not exit then it will create a file there and write your connection string.

If file exist and connecitonstring exists then your first connectionstring asking page will not display.......


这篇关于如何与数据库一起部署Windows窗体应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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