如何将存储在web.config文件中的连接字符串访问到其他层(将类库分类为N层应用程序)? [英] How to access connection string stored in web.config file to the others layer(class libraries into Physical separation as N-Tier Application)?

查看:57
本文介绍了如何将存储在web.config文件中的连接字符串访问到其他层(将类库分类为N层应用程序)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请任何人可以帮助我了解我的项目.我无法将connString从web.config文件访问到在同一解决方案中作为类库项目物理隔离的BO和DA层.虽然我读了很多文章,但我不明白这样的体系结构.我在DA层中有CRUD方法和实体类.我只想验证DA中的DB方法.请任何人帮助我理解这一点,感谢您的合作和鼓励,电子工程师成为软件专家.谢谢

Please can anyone help me to understand my project. I am unable to access connString from web.config file to my BO and DA layers which are physically separated as class library projects in the same solution. Though i have read many articles but I can''t understand such architecture. I have CRUD methods and Entity Classes in DA layer. All I want is to validated DB method in DA only. Please anyone help me to understand this and I shall be thank full for you cooperation and encouragement to Electronic Engineer to become Software Professional. Thank you

推荐答案

AppDomain中的所有库都可以通过ConfigurationManager类(使用System.Configuration)访问web.config数据.
因此,在类库中,
All libraries in the AppDomain have access to the web.config data through the ConfigurationManager class (using System.Configuration)

So in a class library,
string connString = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;


非常感谢您的答复,感谢您的答复,但是如果我需要以类似下面的方式在BaseClass中编写它,我该如何获取我的conString.需要为connStr声明带构造函数的构造函数,不带参数作为connectionString.和朋友的财产.我不知道这两个类应该是私有的还是公共的,但是我在DNNuke站点体系结构中看到过这样的方法.请您以这种方式帮助我,先生,我将非常感谢.我尝试过但是出现很多错误,例如格式不正确"或无效的连接字符串...."
请您能喜欢我如何从一个层访问另一个层.谢谢
I am thankfull for your reply and I appreciate you answer but how can i get my conString if i need to write it in BaseClass in a fashion like below. Need to declare Constructors for connStr with argument and without arguments as connectionString. And a friend Property. I dont know either class should be private or public but such method i have seen in DNNuke site architecture. Please if you can help me in this way then sir i would be very much thankful. I tried But alot of errors like "The format is incorrect" or "Invalid connection String...."
Please could you favour me how to access my classes from one layer to another.Thank you


这篇关于如何将存储在web.config文件中的连接字符串访问到其他层(将类库分类为N层应用程序)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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