在类库项目中获取connectionstring [英] Get connectionstring in a class library project

查看:68
本文介绍了在类库项目中获取connectionstring的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
我正在做一个示例项目,它有3层,如BAL,DAL,PL。

BAL,它将处理所有业务逻辑和DAL,以执行所有与数据库相关的操作,但当我进入DAL时,我很小但很困惑。



要执行数据库操作,我们需要来自Web.Config文件的连接字符串。

我找到了一些在DAL中使用connectionstring的方法,但请告诉我哪个是访问连接字符串以进行数据库操作的最佳方法。



我发现



1.从PL-> BAL-> DAL传递连接字符串(通过方法)

2.从PL-> BAL传递连接字符串 - > ; DAL(通过构造函数)

3.在DAL中添加System.Configuration作为引用并访问连接字符串或在BAL中执行相同的操作并将连接字符串发送到DAL。







感谢您的考虑和时间

Prafulla 解决方案

使用最后一个:DAL负责数据访问,因此它是唯一需要知道需要连接字符串的人。而且需要知道数据库服务器在哪里...路径可能与PL或BL不同,因为它们可能位于不同的计算机甚至网络上。


Refer :

http://stackoverflow.com/questions/9395518/where-should-i-put-my-connection-strings-for-my-class-library-and-how-do-i -acces [ ^ ]

http://stackoverflow.com/questions/18682078/get-connection-string-in-class-library-project-in-a-解决方案 [ ^ ]

这可能会有所帮助。


hi I am doing a sample project which has 3 layers like BAL,DAL,PL.
BAL which will handle all the Business logic and DAL to perform all database related operations but I am little but confused when I entered into the DAL.

To perform database operation we need connectionstring from Web.Config file.
I found some ways to use the connectionstring in DAL but please suggest me which is the best way to access connectionstring for making database operation.

I found

1. Pass the connectionstring from PL->BAL->DAL (through method)
2. Pass the connectionstring from PL->BAL->DAL (through Constructor)
3. Adding System.Configuration as a Reference inside DAL and access the connectionstring or do the same thing in your BAL and send the connectionstring to DAL.



Thanks for your consideration and time
Prafulla

解决方案

Go with the last: the DAL is responsible for data access, so it's the only one which should need to know that connections strings are needed. And it's the one that needs to know where the database server is...the path may be different from the PL or BL because they could be on different computers, or even networks.


Refer:
http://stackoverflow.com/questions/9395518/where-should-i-put-my-connection-strings-for-my-class-library-and-how-do-i-acces[^]
http://stackoverflow.com/questions/18682078/get-connection-string-in-class-library-project-in-a-solution[^]
This may help.


这篇关于在类库项目中获取connectionstring的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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