在3层架构中调用连接字符串 [英] call connectionstring in 3 tier architecture

查看:82
本文介绍了在3层架构中调用连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建3层架构Web应用程序,在3个不同的项目中有3层:

i store连接字符串在表示层web.config文件中



i想要访问数据访问层中的连接字符串;



使用此代码;

ConfigurationManager.ConnectionStrings(sqlcon)。ConnectionString



它给出错误

解决方案

在你的情况下你需要添加System.Configuration组件(。来自您的数据访问项目的.NET框架组件)引用。当您在此项目中添加引用时,数据访问层ConfigurationManager类将工作并能够读取UI项目Web.Config文件并获取您的连接字符串值,如果您正确地注册/添加连接字符串值与键sqcon那里。

i create 3 tier architecture web application with 3 layer in 3 different project:
i store connection string in presentation layer web.config file

i want to access connection string in data access layer;

use this code;
ConfigurationManager.ConnectionStrings("sqlcon").ConnectionString

bt it give error

解决方案

In your case You need to add System.Configuration component(.NET framework component) reference from your Data Access Project. When you add reference with in this project, data access layer ConfigurationManager Class will work and able to read UI project Web.Config File and get your connection string value if you properly register/add connection string value with key "sqcon" there.


这篇关于在3层架构中调用连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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