使用库进行连接时,我应该在C#应用程序的哪里编写Connectionstring? [英] Where should i write Connectionstring in C# application while using Library for Connection?

查看:53
本文介绍了使用库进行连接时,我应该在C#应用程序的哪里编写Connectionstring?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在名为DBConnection的项目中使用连接库,并在另一个库中调用此库,而在Windows应用程序中调用了第二个库
一世. e. 3层架构.因此,问题在于如何在库中添加App.config以及如何在库的类中读取该连接字符串.

我的项目依存关系如下.
DBConnection --To-- DAL库-To-- BAL --To-MyApplication

我是刚开始从事此工作的人,请给我解决方案.
我也想在应用程序数据文件夹中添加我的sqlserver数据库以进行部署,因此再次出现问题,即它如何连接到客户端的服务器,并且它会自动使用我的连接吗?

请有人帮我.

在Advance中致谢

I am using Library for Connection in my project named DBConnection and i am calling this library in another library and this 2 nd library is called in windows application
i. e. 3 tier architecture. So the problem is how can add App.config in library and how to read that connectionstring in the class in Library.

My project dependancies as below.
DBConnection --To-- DAL library -- To-- BAL --To -- MyApplication

I am new to work on this so please give me solution.
Also i want to add my sqlserver database in Application data folder for deployement so again there is problem that how it is connected to server on client side and is it automatically use my connecion?

please somebody help me.

Thanks in Advance

推荐答案

配置信息通常是在应用程序启动时设置的,并且由于它经常更改,因此该信息位于最高级别,即应用程序可执行文件. br/>
您还可以通过文件访问来读取dll级别的配置信息,而您的应用程序可能不知道.

读取配置数据的最简单方法是Dataset.ReadXml().
Configuration information is usually set on the applications startup, and because it is changed often this is put at the highest level, ie the application executable.

You can also read configuration information at the dll level via file access, and your application can have no knowledge.

The simplest way to read config data is Dataset.ReadXml().


App.Config是存储连接字符串的位置.
此处阅读更多信息 [
App.Config is a location where you could store the connection string.
Read more about it here[^].


这篇关于使用库进行连接时,我应该在C#应用程序的哪里编写Connectionstring?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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