部署链接到使用SQL Server创建的数据库的C#Windows应用程序 [英] deploy a c# windows application that is linked to a database created using sql server

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

问题描述

我的一项作业涉及创建一个C#Windows应用程序,该应用程序从使用SQL Server 2005创建的数据库中读取和写入.现在的问题是我必须将代码和正在运行的应用程序提供给CD上的教授.所以任何人都可以告诉我如何将应用程序与数据库一起部署在CD上,以便教授可以从cd运行该应用程序或将其安装在他的计算机上并从那里运行它,并且仍然保持与数据库的连接并读取并写.非常感谢.


在我的应用程序中,我使用Visual Studio 2008中的添加数据源将PS连接到数据库.

I have an assignment that involves creating a C# windows application that reads and writes from a database that I created using SQL Server 2005. the problem now is I have to give the code and the running application to my professor on a CD. so can anyone please tell me how can I deploy my application with the database on the CD so that the professor can run the application from the cd or install it on his computer and run it from there and still it remains connected to the database and reads and writes to it. thank you very much.


P.S in my application i connected to the database using add data source from visual studio 2008.

推荐答案

您可以创建自定义操作来安装数据库-请参见此处 [
You could create a custom action to install the database - see here[^].


首先,除非教授在计算机上安装了SQL服务器并且服务器名称相同,否则无法保持连接状态,但是仍然可以解决问题.

1.)而不是连接到服务器,而是使用原始数据库进行连接(.mdf文件).
2.将数据库(.mdf)复制到调试文件夹.
3.然后使用此连接.
first of all it is not possible to be still connected unless if your professor have a SQL server intalled in his PC and you have the same server name, but there is still solution to your problem.

1.) instead of connecting to server use the original database to connect (the .mdf file).
2. Copy your database(.mdf) to the debug folder.
3. then use this connection.
string databasePath = Application.StartupPath + "\database.mdf";
string connectionString = "DataSource=.\SQLEXPRESS; AttachDbFilename =" + databasePath +";Integrated Security=True;Connect Timeout=30;User Instance=True"
System.Data.SqlClient.SqlConnection  con = new System.Data.SqlClient.SqlConnection(connectionString);
con.open();



重要说明:将数据库(mdf)包含在包中.



IMPORTANT: include the database(mdf) to the package.


尝试此链接
使用VS 2005为Windows应用创建安装项目 [ ^ ]
try this link
Create setup project for windows applictaion using VS 2005[^]


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

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