如何在Windows C#应用程序中创建包含数据库的设置

问题描述:

大家好,首先祝大家新年快乐



现在我的问题是这个。



我想用c#创建一个窗口应用程序。现在我想知道我是否使用sql server数据库然后在完成我的项目后,我将创建设置然后我必须存储数据库。我需要用户在使用我的应用程序之前不必在他的系统中安装vs framework和sql数据库。所以请告诉我数据库的解决方案是什么,它将自动安装在将要安装我的应用程序的用户系统中



Regard

Azad Chauhan

Hi every one first of all wish you all very happy new year

Now My Question is this.

I wanna to create a window application using c#. Now I want to know if i use sql server database and then after completion of my project when i will create setup then where i have to store database. I need that user will have not to install vs framework and sql database in his system before use my application.So please tell me what is the solution for database that it will install automatically in users system who is going to install my application

Regard
Azad Chauhan

最好的方法是使用SQL Server Compact或SQLite,它通过dll和本地文件运行。如果您使用SQL Server Express或任何更大的版本,则需要一个连接字符串,您需要还原您发布的数据库,或运行脚本来创建它。您可以编写代码来假设SQL Server已安装并且可以通过(本地)访问,您也可以编写代码来搜索网络(SQL Server本身就是这样做的,但很糟糕,所以我不会指望它)但是,如果您需要完整的SQL Server,则不能假设用户拥有它,或者您的应用程序可以找到它。



如果是我,我会编写一个C ++安装程序应用程序来安装.NET,运行我的msi,如果它是本地安装SQL Server Express不存在,并配置它。
The best way to do this is to use SQL Server Compact, or SQLite, which runs via a dll and a local file. If you use SQL Server Express or any of the bigger versions, you will need a connection string, and you will need to either restore a DB you ship, or run scripts to create it. You can write code to assume that SQL Server is installed and can be reached via (local), and you can perhaps write code to search the network ( SQL Server itself does that, but badly, so I wouldn''t count on it ), but, if you ship with a need for the full SQL Server, you can''t assume the user has it, or that your app can find it.

If it were me, I''d be writing a C++ installer app to install .NET, run my msi, install SQL Server Express locally if it''s not there, and configure it.