CedricB
03-25-2006, 02:43 AM
Hi,
I'm trying to put together the architecture for a new application. I'm using .net 1.1, ado.net and ms sql server, but I guess my questions also apply to other environments.
A sketch of my situation:
1. I have a database with tables
2. For most tables, I have a class in a code library to control access to it
3. I'm currently building an asp.net application, but I might need to access the same data later on from other environments, e.g. windows application.
What is the best strategy for my database connections? Some thoughts already
1. I won't have my classes read the connection string from the web.config since this will limit them to a web environment only. Hence, I guess I will pass them as a parameter in my constructor method.
2. What to do with transactions that may stretch different classes? Pass an opened connection to the class through a constructor? Of course this violates the open late and close early guideline for database connections. Any alternatives?
3. I'm not currently taking support for other databases in my requirements, but what if I do? How does this affect my strategy?
4. What is the best way to get a list of items, e.g. all users when I have a user class? Passing a dataset is the easiest and quickest, but exposes the database structure outside the user class. Passing a collection of user objects means that I have to create a user object for each row in the dataset before it is returned from the class.
I'm looking forward to hear your thoughts, experiences, strategies, ...
Cedric
I'm trying to put together the architecture for a new application. I'm using .net 1.1, ado.net and ms sql server, but I guess my questions also apply to other environments.
A sketch of my situation:
1. I have a database with tables
2. For most tables, I have a class in a code library to control access to it
3. I'm currently building an asp.net application, but I might need to access the same data later on from other environments, e.g. windows application.
What is the best strategy for my database connections? Some thoughts already
1. I won't have my classes read the connection string from the web.config since this will limit them to a web environment only. Hence, I guess I will pass them as a parameter in my constructor method.
2. What to do with transactions that may stretch different classes? Pass an opened connection to the class through a constructor? Of course this violates the open late and close early guideline for database connections. Any alternatives?
3. I'm not currently taking support for other databases in my requirements, but what if I do? How does this affect my strategy?
4. What is the best way to get a list of items, e.g. all users when I have a user class? Passing a dataset is the easiest and quickest, but exposes the database structure outside the user class. Passing a collection of user objects means that I have to create a user object for each row in the dataset before it is returned from the class.
I'm looking forward to hear your thoughts, experiences, strategies, ...
Cedric