Link to home
Start Free TrialLog in
Avatar of AndrewSQLDBA
AndrewSQLDBA

asked on

SQL Database Conenction Class

Hello All
I am trying to learn more about OOP. I am trying to create a Database Connection Class. I have created other classes and methods, but this one is giving me great trouble for some reason.

I have code in the .cs file that currently works fine to open and close the connection. But that conenction method is written on each and every page. As we all know, that is not a good thing.

A sample of code or a place to find the answer would be greatly appreciated.

Thanks
Andrew SQLDBA
Avatar of RubenvdLinden
RubenvdLinden

Can you paste some of your code? I don't really understand what's your problem.
Avatar of AndrewSQLDBA

ASKER

If I had code that was in a class, I would not have asked.

I want to create a class, that the code does a connection to a SQL database. How do I code that using C#

Andrew SQLDBA
ASKER CERTIFIED SOLUTION
Avatar of sabeesh
sabeesh
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It's good practice to create a new connection object on each page and dispose it when you're finished using it.
Sure, it's a lot of code but using a static connection is not thread-safe.