473,396 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

A reusable connection class to a database

I want my code to call a reusable class to connect to a database. I can't think of a way to write where it is genric. I know the connection string may change, but for the most part the code should be the same. Know any good articles I could read?
Aug 1 '07 #1
3 1954
TRScheel
638 Expert 512MB
I had the same issue you had a few months back. I was sick of writing something similiar each time I needed to connect to the SQL server (That and I absolutely HATE copy/pasting code).

What I did was something like this:

-Classified a SQL item class

-Classified a SQL return collection class (contains a list of item's and code to work on them)

-Classified a few generic SQL calls (insert, request, integer returns, etc) and made them flexible enough to change with differences in the parameters

I could walk you through the same process I went through if you'd like
Aug 1 '07 #2
Yes please walk me through the process, I'm not sure what Classified a SQL item class means, so by all means.

Brent
Aug 2 '07 #3
TRScheel
638 Expert 512MB
Yes please walk me through the process, I'm not sure what Classified a SQL item class means, so by all means.

Brent
Alright, I assume you have a few functions already that do work on your database. What you need to do now is find their similiarities. If you'd like, I can help you with this process if you post code.

** NOTE ** Take out any:

Websites/Address
Usernames
Passwords
Anything else that might be unwise to post on the internet.

____________________

When doing my code, I noticed that there were a few basic implementations. I would either:

A) Request data
B) Request a data reader
C) Request a scalar
D) Insert a row

(There is more you can do, but those were the four implementations I did for that project)

Once done with that, I took apart each item, and realized that fundamentally they were the same. The only difference lies in how they reacted with the Sql objects. I tore out the creation of the SqlConnection and SqlCommand objects, and created seperate functions only for the different actions I would do on them, not on the creation / disposal of them.
Aug 3 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: JWM | last post by:
I am trying to implement Oracle connection pooling for the following code, which was written by someone else. Here is my main question -- this java file creates code that is executed every hour,...
2
by: John | last post by:
Hi, I have a data driven application which has some generalized components. So, for reuse, I am building the components so they can be reused in other projects ... it takes almost no extra...
2
by: DaleMan | last post by:
Where can I learn more about reusable businesss objects and their uses? I've been reading that one of .Net's advantages is that a developer can write reusable business objects. I would like to...
2
by: Bryan | last post by:
Hello, I'm just starting to develop in asp.net and i have a question about using a database connection globally in my app. I have set up the procedures for getting all my connection string info...
35
by: Eric Sabine | last post by:
In my Finally block, I was using cn.close (where cn is an ADO.NET connection object, SQLConnection to be exact) and then I came across the following in some microsoft code. If Not cn Is Nothing...
35
by: Terry Jolly | last post by:
Web Solution Goal: Have a global database connection Why: (There will be 30+ tables, represented by 30+ classes) I only want to reference the database connection once. I put the connection...
1
by: Sankalp | last post by:
Hi, I am using VB 2005. My application has many data bound controls. The connection is stored in the app.config file. I want the application to start with a default connection string and while...
0
by: fiona | last post by:
Reading, Berkshire, UK 05 June 2007 - Crainiate Software make details available of the release of Objecto Framework 2.0, an upgrade to their enterprise business component framework, designed to...
1
by: dellis | last post by:
Problem: My project was initially created without putting passwords in the connection string. When I added the password in the connection string, it disappears when performing a database fill. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
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,...

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.