Net应用程序的连接字符串

Net应用程序的连接字符串

本文介绍了指导需要ASP.Net应用程序的连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.NET 2.0 / Visual Studio 2005中/ ASP.Net Web应用程序

Net 2.0 / Visual Studio 2005 / ASP.Net web app

我读了这个网站的许多文章和评论,但不是有些太混乱跟着我或其他人不符合我的要求。

I read many posts and comments on this site but either some are too confusing to follow for me or others don't meet my requirement.

所以我有一个3层应用程序 - UI,BLL,DAL。在我的DAL,我从服务器资源管理器draggin storedprocedures创建数据集。因此,连接字符串变得困难coded到数据文件中。

So I have a 3 tier application - UI, BLL, DAL. In my DAL, I created DataSets by draggin storedprocedures from the Server Explorer. So the connection string got hardcoded into the dataset file.

我想AP preciate有人解释简单的一步一步的是我一定要这样,当我通过在UI连接字符串(主体工程)设置设计师下降到BLL和thenn下降到DAL。

I would appreciate someone explaining simple step-by-step what I must to so that when I pass connection string in the UI (main projects) Settings designer down to the BLL and thenn down to the DAL.

推荐答案

这是一个非常有趣的场景,我已经通过在此之前,因为我在多层应用程序有时使用的数据集。因此,这里的解决方案。

This is a very interesting scenario and I've been through this before since I use dataset sometimes in my multi-tier apps. So here's the solution.

我想除了UI都是对BLL,DAL类的lib项目。在DAL你不得不DataSet设计这使在连接字符串中的DAL类LIB PRJ的的app.config下。现在,如果你需要参阅的BAL这又是一个类的lib PRJ的DAL以上,从DAL的app.config中复制connectionStrings节并将其粘贴到BAL的App.config中的CLASSLIB PRJ的connectionStrings节。在这里,你必须看到,在连接字符串名称不只是'myDataBaseConnStr。这将会是有详细的命名空间引用,如MyApp.DataLayer.DataSet.myDataBaseConnStr。同样的过程中,你应该UI层的app.config或web.config文件执行。一旦你这样做成功,你可以在你的UI层的应用[web.config文件或app.config中]根配置文件中的connectionString改变。这样,它总是从皮卡UI层的connectionString因为这是在运行时正在执行的AppDomain。所以,你可以在那里更改连接字符串,并将其体现在底层的BAL和DAL。

I assume apart from UI all are class-lib projects for BLL, DAL. In the DAL you'd have the dataset designer which puts in the connection string under the app.config of the DAL class-lib prj. Now if you need to refer the BAL above the DAL which is again a class-lib prj, copy the connectionStrings section from the app.config of DAL and paste it to connectionStrings section of the app.Config of BAL classlib prj. Here you must notice that the connection string name is not just 'myDataBaseConnStr'. It'd be with detailed namespace reference, like MyApp.DataLayer.DataSet.myDataBaseConnStr. Same process you should perform with UI layer app.config or web.config. Once you've done this successfully you can change in the connectionString in root config file of your UI layer app [web.config or app.config]. This way it will always pickup the connectionString from UI layer since that's be the executing AppDomain at runtime. So you can change the connection string there and have it reflected in underlying BAL and DAL.

感谢。

这篇关于指导需要ASP.Net应用程序的连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 23:16