473,466 Members | 1,397 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Web Layer & Business Layer communication

Hi,

I'm programming a web site and I separated the web UI layer from the
business objects layer...
But the objects in the business layer needs a query string for database
access.. The client (the website) is responsible to provide this connection
string.

Right now, every time a page needs to interact with a business object
(methods), the web page pass the connection string to the businees object
(each methods of the business objects has a connectionstring parameter).

Instead of doing this, I thought that I could initialize the business layer
with my connection string in the Application Start only once. ie.:
BusinessLayer.ConnectionInfo.ConnectionString =
ConfigurationManager.ConnectionStrings[...].Con[...]; The business objects
would then refer to BusinessLayer.ConnectionInfo every time it has to
connect the to the database...

But I don't know how to propery do that with static objects and
multi-threads implications and all that stuff... Is my idea good? How do you
guys proceed in those scenarios!?

Thanks

Mike
Oct 30 '08 #1
5 2676

Can't you just pass down the DatabaseKeyName to the BusinessLayer?
Maybe in the constructor of your BusinessLayerControll objects?

Go here:
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!140.entry

Get the code:
Change

public class CustomerController
{
public CustomerController()
{

}
to

public class CustomerController
{
private string _dbInstanceName = string.Empty; //DatabaseKeyName

public CustomerController(string dbInstanceName)
{
_dbInstanceName = dbInstanceName;
}
Then push that value to the DAL.

And instead of

["MyAppConnectionString"]

You'll use the

[dbInstanceName] .. that you sent from the BAL to the DAL.

Download my code sample, it'll make sense then.


"Mike Gleason jr Couturier" <no****@invalidhost.comwrote in message
news:eL**************@TK2MSFTNGP03.phx.gbl...
Hi,

I'm programming a web site and I separated the web UI layer from the
business objects layer...
But the objects in the business layer needs a query string for database
access.. The client (the website) is responsible to provide this
connection string.

Right now, every time a page needs to interact with a business object
(methods), the web page pass the connection string to the businees object
(each methods of the business objects has a connectionstring parameter).

Instead of doing this, I thought that I could initialize the business
layer with my connection string in the Application Start only once. ie.:
BusinessLayer.ConnectionInfo.ConnectionString =
ConfigurationManager.ConnectionStrings[...].Con[...]; The business objects
would then refer to BusinessLayer.ConnectionInfo every time it has to
connect the to the database...

But I don't know how to propery do that with static objects and
multi-threads implications and all that stuff... Is my idea good? How do
you guys proceed in those scenarios!?

Thanks

Mike

Oct 30 '08 #2

"sloan" <sl***@ipass.neta écrit dans le message de news:
u6**************@TK2MSFTNGP06.phx.gbl...
>
Can't you just pass down the DatabaseKeyName to the BusinessLayer?
Maybe in the constructor of your BusinessLayerControll objects?

Go here:
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!140.entry

I see... that's because my Business Objects are static classes:

ie.: MyUser u = BusinessLayer.MyUser.Authenticate(user, pass);

So the Authenticate method must take its connection string from somewhere...
right now, its:

MyUser u = BusinessLayer.MyUser.Authenticate(connString, user, pass);

Mike
Oct 30 '08 #3

Now you know the one little tiny reason I use non static classes for
controllers.
I can have an overloaded constructor, so I can rely on the default db...or
use a different dbInstanceName.
You can (do what you put in your previous post) HOWEVER: ... I would rename
your parameterName:
MyUser u = BusinessLayer.MyUser.Authenticate(dbInstanceName , user, pass);
OR
MyUser u = BusinessLayer.MyUser.Authenticate( databaseKeyName , user, pass);
Because it would be risky to keep passing full connection strings down.

You can "name" your connection strings.

<connectionStrings >


<add name="SalesDB" connectionString="server=.;database=MyDB1;Integrat ed
Security=SSPI; Pooling=false; " providerName="System.Data.SqlClient"/>

<add name="CustomerDB" connectionString="server=.;database=MyDB2;Integrat ed
Security=SSPI; Pooling=false; " providerName="System.Data.SqlClient"/>

</connectionStrings>

In this case, I would pass down SalesDB or "CustomerDB", the KEY name, not
the connection string.

"Mike Gleason jr Couturier" <no****@invalidhost.comwrote in message
news:OD*************@TK2MSFTNGP06.phx.gbl...
>
"sloan" <sl***@ipass.neta écrit dans le message de news:
u6**************@TK2MSFTNGP06.phx.gbl...
>>
Can't you just pass down the DatabaseKeyName to the BusinessLayer?
Maybe in the constructor of your BusinessLayerControll objects?

Go here:
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!140.entry


I see... that's because my Business Objects are static classes:

ie.: MyUser u = BusinessLayer.MyUser.Authenticate(user, pass);

So the Authenticate method must take its connection string from
somewhere... right now, its:

MyUser u = BusinessLayer.MyUser.Authenticate(connString, user, pass);

Mike

Oct 30 '08 #4
>
You can (do what you put in your previous post) HOWEVER: ... I would
rename your parameterName:
MyUser u = BusinessLayer.MyUser.Authenticate(dbInstanceName , user, pass);
OR
MyUser u = BusinessLayer.MyUser.Authenticate( databaseKeyName , user,
pass);
Because it would be risky to keep passing full connection strings down.
But What if the data layer is used in a Desktop Environment where it does
know a thing about a web.config?

Thanks!

Mike
Oct 31 '08 #5
Forget my last post, applications uses the same approach with config files!
Oct 31 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Michael Rodriguez | last post by:
I have a windows form that makes a call to my BLL to get some data. The windows form has a progress bar component that I would like updated as the data retrieval takes place. However, strictly...
2
by: headware | last post by:
I'm relatively new to ASP.NET and ADO.NET, but I have a basic design question regarding the use of web services and APS.NET applications. Right now we have an application that uses web services to...
1
by: rbg | last post by:
Hi, I am trying to understand the layering concept with the ASP.NET 2.0 apps. I have a ASP.NET 2.0 Web app which has 3 layers Presentation layer which contains UI elements and Input...
16
by: MS newsgroup | last post by:
I don't have clear reasons why we need business logic layer and data logic layer instead of having only data logic layer. Are there any good reasons for that?
3
by: olduncleamos | last post by:
Hi all, What is, in general, the preferred practice to transfer data between business objects and the data layer? To be more specific, I have a couple of business objects with state data that...
6
by: Dhananjay | last post by:
hello everyone i have got a problem i want to design business layer, data access layer , presentation layer for asp.net using C#.net , can anyone help me to solve this problem. i want some...
8
by: morleyc | last post by:
Hi, until recently i was quite happy to add data sources from mssql database in visual studio and drag the datasets directly onto the form this creating a directly editable form which worked well....
0
by: SumanM | last post by:
A company wants to conduct its initial screening test for recruitment using a web based online test. Presently, the test should consist of two parts -- .NET and RDBMS (Questions on SQL Server &...
9
by: SAL | last post by:
Hello, I have a Dataset that I have table adapters in I designed using the designer (DataLayer). I have a business logic layer that immulates the DataLayer which may/may not have additional logic...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.