如何在c#中使用两个应用程序/项目使用一个数据库 [英] How to use one database by two application/project in c#

查看:234
本文介绍了如何在c#中使用两个应用程序/项目使用一个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio 2008 Express Edition中使用Microsoft SQL Server 2005,我的一个应用程序是更新数据库,另一个是使用其数据查看数据库的内容。更新应用程序工作,当我去我的其他应用程序并查看数据库的内容我的数据库是空的。为什么?

I use Microsoft SQL Server 2005 in my Visual Studio 2008 Express Edition,my one application is to update the database, and the other is to view the contents of the database with its data. The update application works, when i go to my other application and view the contents of the database my database is empty. Why?

推荐答案

我只是使用数据库的数据集。



在你的第二个申请中/项目执行以下步骤:

1.右键单击项目

2.添加现有项目

3.选择数据库数据集,扩展名应该是'.xsd'



你可以使用Datagrid或Crystal报告查看数据库的数据。



***注意****

在您的连接字符串中,请按照以下步骤操作:

1.右键单击项目

2.选择属性

3.选择设置



从那里只需添加你的连接名称,

类型:字符串

范围:应用

值:数据源= .\SQLEXPRESS; AttachDbFilename =数据库的路径; Integrated Security = True; Connect Timeout = 30;用户实例=真



例如:

数据源= .\SQLEXPRESS; AttachDbFilename =C: \\ Users\user\Documents\Visual Studio 2008 \Projects\Massaji\Massaji\MassajiDatabase.mdf; Integrated Security = True; Connect Timeout = 30; User Instance = True
I just use the dataset of the the database.

In your second application/project do these steps:
1. right click the project
2. add existing item
3. select the database dataset, the extension should be '.xsd'

There you go, you can now view the data of the database using Datagrid or Crystal report.

***Note****
In your connection string follow these steps:
1. right click project
2. select properties
3. select settings

from there just add the name of your connection,
Type: string
Scope: Application
Value: Data Source=.\SQLEXPRESS;AttachDbFilename="the path of the database";Integrated Security=True;Connect Timeout=30;User Instance=True

example:
Data Source=.\SQLEXPRESS;AttachDbFilename="C:\Users\user\Documents\Visual Studio 2008\Projects\Massaji\Massaji\MassajiDatabase.mdf";Integrated Security=True;Connect Timeout=30;User Instance=True


这篇关于如何在c#中使用两个应用程序/项目使用一个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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