Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I've got a 'rookie' question :)
I want to write an application in C# with database in SQL Server 2008.

The application will save in database logs, settings, users accounts..

I want to ask you about the connection between app and DB.
Could you recommend me a sample project ?
I mean - I know how to use ADO.NET, how to connect, send command... I just need an example - to see how it looks in the solution.

Thanks for your time.

-----------------------------------------------------------------------------
edit:
Maybe this sounds wierd, because at the top I wrote 'rookie', but:

I'm not looking for samples for beginners, I would like to look at 'pro' soultion.
I mean.. I'm looking form some pattern - which profesjonal programmers use in profesjonal applications.

For example - create project named 'Data', create class DatabaseProvider.cs or DataRepository.cs or QueryRepository.cs.. where to keep connection string. I don't know.

Maybe I shound ask like that: I'm looking for pattern, how to create 'Data' project (class library) in my program solution, which will be responsible for connectivity with SQL server 2008.

Thanks, once again



-----------------------------------------------------------------------------
EDIT 2:
So, this will be windows service application, which will be host for WCF sevices. Windows service application have to get data from database to configuration, save logs, store accounts data.. and store some other things.

My first thought was to create separate project: <solutionname>.Data, and inside create classes:
DatabaseProvider.cs - in here, i will access database, insert, update or select data.
QueryRepository.cs - defined queries, used in database provider

IDataRepository.cs - methods used in whole solution to access database (eg. GetSettings();)
DataRepository.cs - defined IDataRepository.cs
eg.
public int GetSettings()
{
using (DatabaseProvider db = new DatabaseProvider())
{
return db.GetSettings();
}
}
and App.config with connection string.

In DatabaseProvider.cs I use ADO.NET to access database.
But, now I'm not sure, if I will be able to get SysId (primary key, column in table), after insert operation on this table.



Now I'm reading "Designing Data Tier Components and Passing Data Through Tiers" article (however - it is outdated - so I'm not sure if the solutions are the best right now).
Posted
Updated 2-Jul-11 6:04am
v3
Comments
Mario Majčica 1-Jul-11 13:15pm    
What is the UI that you will use, ASP.NET, WinForms, WCF, etc...???
Uday P.Singh 2-Jul-11 2:06am    
Do you want to make a web(asp.net) application or desktop(winform) application?
mnd017 2-Jul-11 12:05pm    
thanks for the answer, edited the question again

Looking at the edit block, the desing of your data tier components should really depend on your system requirements, there is no one design/patterns fits all. However, following link should be of great help:

Designing Data Tier Components and Passing Data Through Tiers[^]

Also, choice of technologies such as Entity Framework, Data Access Application block should be considered and evaluated.

----------------------------------------
Here you go:

Refer to these links
Using ADO.NET for beginners[^]

ADO.NET Code Examples[^]

ADO.NET Sample Application[^]
 
Share this answer
 
v2
Comments
mnd017 1-Jul-11 13:59pm    
Thank you for your time and answer. Look at my "edit" in question.
 
Share this answer
 
Comments
mnd017 1-Jul-11 13:59pm    
Thank you for your time and answer. Look at my "edit" in question.
I would suggest you to use Enterprise Library 5.0 Data Application Block

Other than that, you can use some good pattern blocks available in codeplex site.

Thanks
Subhendu
 
Share this answer
 
Comments
RaviRanjanKr 2-Jul-11 14:04pm    
Nice Link! My 5 :)
mnd017 2-Jul-11 14:35pm    
Thank you,
Could you recommend me a project in C# connected with SQL server 2008 - but not web project? from this codeplex site?

Enterprise Library 5.0 - I think is a huge and complected tool and I don't have much time for learning it now.
I have done at: http://mcsoft.com.vn/ConnectToSQLServer.aspx

Kind regards,
Minh
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900