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).