如何为包含相关sql数据库的窗体应用程序创建一个设置? [英] how to create a setup for window form application including the related sql database?

查看:96
本文介绍了如何为包含相关sql数据库的窗体应用程序创建一个设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个只有2个表单的简单窗口表单应用程序项目..

第一个用于登录,它将从数据库中检查用户ID密码。如果两个都是正确的那么它将转到第二种形式。

现在我希望这个项目在另一台计算机上运行。

i创建了一个安装文件,但它显示了一些关于数据库实例连接的错误..

所以,如果有人能详细告诉我如何创建安装文件,那么它将提供很大帮助..

提前提交..

i have created a simple window form application project that have only 2 form..
1st one for login in which it'll check the userid n password from database.if both are correct then it will go to 2nd form.
now i want this project to run in another computer.
i created a setup file but its showing some error regarding the database instances connection..
so if anyone can tell me in details how to create the setup file then it'll b a great help..
thanx in advance..

推荐答案

首先检查您的连接字符串,如果您使用计算机的名称作为数据源,然后将其更改为Data Source =。\sqlexpress,在创建安装文件时,您需要在必需的先决条件下选择SQL Server选项也应该使用包含恢复数据库代码的安装程序类(请参阅此文章以创建用于恢复数据库的安装程序类使用Click Once恢复SQL Server Express 2008数据库 [ ^ ])。然后在其他系统中安装应用程序
First check your connection string if u use your computer's name as the datasource then change it as Data Source=.\sqlexpress, While creating setup file you need to select SQL Server under the required prerequisites option also u should use installer class which contains code to restore DB(refer this article for creating installer class for restoring DB Restoring SQL Server Express 2008 Database with Click Once[^]).Then install your application in the other system


将sql数据库文件附加到c#中创建.exe安装程序: -



我们可以实现自动附加数据库只需使用以下连接字符串。



1)将一个名为DB的文件夹添加到项目中,并在将数据库文件从sql server中分离后将其复制到其中。

2)更改你的连接字符串:

< connectionstrings>

< add name =WindowsFormsApplication1.Properties.Settings.BabakConnectionString>

connectionString =Data Source = .; AttachDbFilename = | DataDirectory | \ DB\Babak.mdf; Initial Catalog = test; Integrated Sec urity = True

providerName =System.Data.SqlClient/>





3)在这些之后,数据库文件将在您运行应用程序时自动附加到sql server,并且数据库名称为test,您可以打开sql server management studio查找它。



此外,您可以通过vs2010中的解决方案资源管理器在app.config文件中找到该连接。您还可以在项目下找到此文件。有了这些信息,您可以找到并修改它。
Attach sql database file to creating .exe setup in c# :-

We can implement auto attach database just use the connection string following.

1) Add a folder named "DB" to the project, and copy the database file into it after you detach it from your sql server.
2) Change your connection string like this:
<connectionstrings>
<add name="WindowsFormsApplication1.Properties.Settings.BabakConnectionString">
connectionString="Data Source=.;AttachDbFilename=|DataDirectory|\DB\Babak.mdf;Initial Catalog=test;Integrated Security=True"
providerName="System.Data.SqlClient" />


3) After these, the database file will auto attach to the sql server when you run your application, and the database name is "test", you can open the sql server management studio to find it.

In addition, you can find the connection in the app.config file through the solution explorer in vs2010. And you also can find this file under your project. With these information, you can find it and modify it.


如果第二台计算机使用Windows操作系统,则无需在该计算机上安装应用程序。只需复制可执行文件;)



如果您使用SQL Server数据库并希望通过LAN连接它,则需要启用SQL Server TCP / IP连接 [ ^ ]。



请记住检查Murugan Kolanji提到的连接字符串。



下次,请更具体,并提供更多详细信息。
If a second computer uses Windows OS, then you don't need to install your application on that computer. Just copy executable file ;)

If you use SQL server database and want to connect it via LAN, you need to enable SQL Server TCP/IP connections[^].

Remember to check connection string as Murugan Kolanji mentioned.

Next time, please be more specific and provide more details.


这篇关于如何为包含相关sql数据库的窗体应用程序创建一个设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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