Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preferred method for connecting C# to a database 1

Status
Not open for further replies.

glyn6

Programmer
Nov 2, 2009
561
GB
I know this might be a bit of an openended question but what's considered the best way/method/technology for connecting c# to a sql server?

And does anyone have any links to samples of the same?
 
ado.net is the basis for all RDBMS access.

your primary concerns with ado.net are connections, commands, readers and transactions.

connections: IDbConnection: open, close and create transactions
commands: IDbCommand: the sql statements. use parametrized querys. there is not excuse for injected sql.
readers: IDataReader: when you read data from the database it's loaded into the data reader. from there you load the data into DataSets, DataTables, or your own POCOs (plain old compiled objects).

I have an FAQ which details an approach to using ado.net within asp.net. some of the concepts carry over to desktop applications. the link is in my signature below.

There are also a number of 3rd party frameworks that ease the use of data access. all of them are built on top of ado.net.

MS DataAccess is designed to execute stored procedures (or dynamic sql) and uses DataSets as the primary data structure within your code.

MS recently released another data access model which mirrors php's data access api.

then you get into ORM (object relational mappers)
the big 3 are
Nhibernate (oss)
Castle.ActiveRecord (oss)
MS Entity Framework
Solution Designs, LLBL Gen Pro ($)

you may also read about Linq2Sql. that technology was replaced in favor of Entity Framework.

that should be enough to get you started:)

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Lovely ta, that'll be my reading sorted for the weekend :)
 
the Data Access Block is good if use procs and data sets heavily.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top