I'm building a C#/WPF job search tracking application to keep track of resumes submitted, interviews, followups, etc and am not sure of the best way to store the data. Where/how would YOU store the data? My first thought was XML to keep it simple, but it seems like I should "model" my data since there will be lots of related bits of information. Would SQLite be a better choice? Other recommendations?
Since I assume you want to query and update that data I would even suggest an ORM like Entity Framework - it's easy to get started and the basic stuff like querying and updating will be very straightforward if you have worked with LINQ before - saves you the hassle of writing your own SQL queries. This also will allow you to easily extend your model later on should you decide to do so.
Edit:
There are self-contained light-weight alternatives that would still allow you to use LINQ:
SQL Server Compact:
Microsoft SQL Server Compact is a free
SQL Server embedded database ideal for
building standalone and occasionally
connected applications for mobile
devices, desktops, and Web clients.
Here' an article that describes how to get LINQ to SQL to work on it. Apparently you can also use LINQ to Entities on it but there's quirks (such as design-time support) that you'll have to work around.
SQLLite:
SQLite is a software library that
implements a self-contained,
serverless, zero-configuration,
transactional SQL database engine.
SQLite is the most widely deployed SQL
database engine in the world.
There's a LINQ provider for it called DBLinq
As #Robert Harvey pointed out in his answer there's (almost) full support for EF since there's an ADO.NET provider for SQLLite:
Support for the ADO.NET 3.5 Entity
Framework
Supports nearly all the
entity framework functionality that
Sql Server supports, and passes 99% of
the tests in MS's EFQuerySamples demo
application.
Generally, you want to store the data from your application in a database. For WPF and C#, that database is usually SQL Server or SQL Server Express, because Visual Studio 2008 easily integrates with those.
Do not use XML for this. XML is not intended to be a large scale storage medium; the purpose of XML is to provide a common language for different computer systems to talk to each other.
SQL Server Express is usable on any Windows PC; you just need to deploy the redistributable, using a named instance. See also http://msdn.microsoft.com/en-us/library/dd981032(SQL.100).aspx. If it's a small application and you want to go simpler, you can use SQL Server Compact Edition, or SQLite with the ADO.NET provider.
Related
I am developing a Microsoft Kinect game (for Windows) using C# and I need a local database to store information about players and their progress as well as more detailed information on their points and accuracy. I have never used a database within a Windows application and I was looking for some advice on how to do so. I have been trying to use SQL Server because it lets me create a database within Visual Studio. I have been unable to find many resources on how to interact with the database from within the C# application.
I really know very little about SQL Server so I do not know if it is the right choice for what I need. Does anyone have a suggestion for what sort of database system to use? Can you point me in the direction of some good resources/examples on how to do what I need to do?
Thanks so much!
Edit: I should also mention that I do have experience working with SQL.
There are other, more portable, solutions such as SQLite and SQL Server Compact Edition which do not require a separate server installation and are more easily accessed and distributed from within a standalone desktop application.
The usage can be largely compared to an external SQL server and/or Linq to SQL so the actual implementation should not be that hard.
Some interesting links:
How to: Deploy a SQL Server Compact 4.0 Database with an Application
An Introduction to SQL Server Compact Edition
As mentioned in another comment, a simple serialized XML file might also be enough for your use. It's fast, easy and if you don't need to perform any actual database operations but simply save and load everything then it might be more efficient.
Look into using a SQLDatasource and relevant tutorials. This will give you an easy way to get up and running without an intimate knowledge of SQL. Once you have the datasource setup and 'bound' to your database, you can use this to connect your controls (grids,labels,textboxes ect.) to it.
Check this out:
http://www.youtube.com/watch?v=w34BDhDPEEQ
You don't want the fully fledged SQL Server. SQL Server Compact Edition is more appropriate, or there's also SQLite for a non-Microsoft option.
The easiest way to interact with a database from C# is Entity Framework, which ships with .NET 4.5 or is downloadable as a nuget package for .NET 3.5 and .NET 4.
A different, non-relational-database option would be DB4O.
You could use Entity Framework
var player = db.Players.Where(x => x.playerId = id);
var points = player.points;
points =+ 100;
db.SaveChanges();
You could also write CRUD operations against the tables if you don't want to use an ORM
Basicly you will have to make a database with a table, using the GUI of Visual Studio.
Then where necessary in the code, you will have to create a connection with the database using a connectionstring. Then you will have to insert an SQL command using the SQLCommand class and execute it. This requires some knowledge about the SQL syntax, but just search what kind of command you want specifically now and in time you will get the hang of it. Don't forget to close the connection to the database when you are ready with writing or reading data.
I hope this gives the main idea.
Edit: Oh and for this kind of database SQL Server Compact will be enough.
I am developing a small application with ASP and C# in .NET and I want to have a small local database next to it where I can save and retrieve records by either SQL queries or Linq queries. I don't need anything powerful, just something to use instead of keeping records in .txt files.
So what's your suggestion?
Use SQLite
It does not have to be installed and is just a DB File and there are connectors to .Net available.
And you can use LINQ
I would go with either SQLLite or with XML since you are saying very small database.
And with xml you can use Linq to xml
You can use SQL CE or SQLite.
Best to use SQL Express edition since it comes for free. Try using .NET entity framework code first for rapid application development.
In any case application is very small consider using SQL express since you can write neat and clean stored procedures and can play with other database objects.
Please refer http://www.microsoft.com/sqlserver/en/us/editions/express.aspx for more details.
I'll consider SQLite for this purposes.
If you are more comfortable with MS tools, or for some reason (i.e. your company already has a well formed mdb database file) you can use MS Access too, for local and small applications.
I recommend you to use SQL Server Express, becuase
It is free to use and easy to install
You can easily use either Entity Framework or LINQ TO SQL to manipulate your data
It can easily communicate with your company's DB ( if it is also SQL Server), for example, one day in the future, you may need to test the replication.
No one's mentioned it yet so here it is. mySQL and the .Net mySQL client.
In your case I would consider the following:
XML if you don't with more than a couple hundred records in all tables. And #Ali mentioned already LINQ to XML what will be handy.
VistaDB, because it's 100% managed code and require deployment of just one small assembly for both 32- and 64-bit.
SQL CE, just because it's the most popular one. Of course, it supports LINQ and concurrency.
SQLite as an alternative for SQL CE :)
Don't go with SQL Express unless it's been already provided by your hoster. It increases complexity of distributing/installing of your solution.
I need a lightweight database engine for a desktop application. The application is not data centric, although it needs some persistent data. Which one would you use MS SQL Server express edition or SQLite?
EDIT
Is SQL Server Compact edition free? If it is the case, what about SQLite vs SQL Server Compact edition to develop this kind of application?
Definitely NOT Sql Server Express. That's a server class engine. You want an in-process engine. In that regard, SQLite is fine. So is Sql Server Compact Edition. Both are free and either should be adequate for your needs.
If you're working with C# and Visual Studio simply right-click on your project and select "Add Item..." and in the dialog select the "Local database", this will create a SQL CE (Compact Edition) database. It's got most of the functionality of SQL Express/Server as far as tables, data types, views but doesn't allow stored procs. It also works with Linq-to-SQL so it's a snap to integrate.
Go with SQL Server Compact - you get to use LINQ that way, which itself is worth the effort.
While SQLite is an option, you'll need to get an ORM layer, and the performance gain will be minimal / non-existent compared to SQL Server.
Firebird is a well known database and support the latest Microsoft framework
SQLite, especially if it's single-user. One data file and one DLL.
If its a single user system you want to look at MS SQL Server compact edition not Express (see here: http://www.microsoft.com/sqlserver/2008/en/us/compact.aspx )
Compact Edition is an embedable database similar to SQLite.
Unfortunately I can't make a recommendation either way.
What about MS SQL Server Compact?
Some love for one of the up and comers in the .NET embedded db world -- VistaDb. The license is a bit more restrictive than Sql Server Compact (free to single developers only), but its a 100% managed DB with xcopy deployment and has VS tool integration.
Be aware that if you use SQL CE along with EF, you will have to generate your own id key, because SQL CE does not support multiple query.
i.e:
insert -> select key for the entity -> not good
generate and id key (GUID or something else) add it to your entity and then insert -> good
Defo SQL lite, although it has some restrictions/features that you should be aware of
if your need is data centric, what you really need is a file, if you need transaction (ACID) then your need is (rdbms) database.
Otherwise you'll have issues when up scaling.
If it's not a lot of data, and you don't need to run complicated queries (although LINQ can), why not use an XML Dataset? That way it's platform independent (could run on Linux with Mono) and doesn't require the user to install extra resource hogging software.
I use XML Datasets extensively for applications that require persistent data storage of small amounts of information. If it's only a few variables, you can also use a settings file, and it will be stored either per application or per user depending on your choices.
Think about overhead for your end users ... SQL Server Express still takes up resources, takes time to start up on a reboot and so on. For a small amount of single-user persistent data I would go with SQLite. Unless you're doing serious binding and so on you won't need an ORM between you and it.
Complete newbie question here: I'm just playing with C# for the first time and want to make a Windows Forms application which stores some info in a database structure, but obviously don't want to require something like MySQL to be installed on each client's computer. How do I go about this?
You can use SQLite. It doesn't require any installation or server on the client's computers. Here is an blog describing how to use it with .NET. It is easy to use, just add a reference to the System.Data.SQLite.dll.
Here is an open source data provider for .NET: System.Data.SQLite
From homepage: "SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. SQLite is the most widely deployed SQL database engine in the world. The source code for SQLite is in the public domain."
You use a database that doesn't require an install. There are a few out there - there's Microsoft SQL Server Compact, which frankly is badly named, as it won't support the more useful SQL functions like stored procedures, views and so on. There's also VistaDB which does support stored procs, but requires purchase if you want Visual Studio plugins.
The answer is Embedded Databases. You've got quite a large list of Embedded databases that you can use:
Commercial:
VistaDB - This database is written completely in managed C#.
Open Source:
Firebird - .NET Driver
SQLite - .NET Driver
You could write your data to XML files, or you could take a look at the Sql Server Compact Edition.
You could also work with objects and serialize/deserialize these to disk as binaries.
Of course the type of storage you choose depends a lot on the kind of data you're storing (and the volume of it).
Use SQL Server CE
An easy way to do it from .NET 3.5 onwards is to store your data in XML files and use Linq to XML. This allows you to use SQL-like commands on your data which are actually compiled into your application, so you get full IDE IntelliSense support and error checking.
Perhaps you could serialise a dataset and save it as XML. I'm a little confused why if you're playing around you would need to install MySQL on all client's computers. You could look at using SQL Express which is free perhaps?
Serialise Dataset:
http://blogs.msdn.com/yosit/archive/2003/07/10/9921.aspx
http://msdn.microsoft.com/en-us/magazine/cc163911.aspx
The Easiest way will be SQL Server Compact, Because it integrates directly into the Visual Studio IDE (I'm just hazarding the guess here that you use VS). Add the "Local Database", Create your tables and be sure to make your Table Adapter with Select, Update, Insert and Delete methods. If during Database Creation you called your Dataset "DS" you will be able to instantiate a Table Adapter Object from
DSTableAdapters
Namespace, and Use GetData() or Fill() methods to retrieve your Data, and Insert(), Update() and Delete() to Manage it.
VelocityDB works in a server less mode but can also be combined with a server when there is a need for it. It outperforms all the other choices mentioned here by roughly a magnitude, see comparison here. It allows you to use almost any .NET data structures persistently. The entire database engine and the optional server is implemented using C# code.
I'm creating a small database application to teach myself the following concepts
C# programming
.Net 3.5 framework
WPF
LINQ ORM
I want to use Microsoft Access as the database but I can't seem to find any mention of whether its possible to use SQLMetal to generate the ORM code from a Microsoft Access database.
Does anyone know if this is possible?
If not, are there any small database or embedded databases I could use? I think SQL express would be overkill for me at this point.
For an embedded database, you can use SQL Server Compact Edition. Unlike SQL Server Express, it is not compatible with the LINQ to SQL designer, but it is fully compatible with the command-line SQLMetal. It has a few advantages over SQL Express, like to ability to use embedded or run from a file. Microsoft has a very handy chart outlining the differences between Express and Compact.
I don't think SQL Express would be overkill if you want to learn real-world skills - quite the opposite in fact! That'd be my choice, and whatever I chose, I'd stay clear of Access.
Good luck
AFAIK, Linq to SQL is MSSQL server provider specific. To be honest, SQL Express is pretty lightweight on todays machines.
BTW don't confuse LINQ with Linq to SQL. Linq is the underlying technology to provide "query" like support to .NET (amongst other things), where as L2S is effectively a Data Access technology built on top of Linq. Vanilla Linq will work with any ADO.NET provider, which of course Access is one.
Entity Framework will work with any compatible provider also but if SQLExpress is too heavy for you then I wouldn't recommend going down this path...
Thanks for all the responses. I never expected to get an answer this quick. For my test application I think SQL Server Compact Edition would be the way to go. I'm basically creating a money managment app similar to Microsoft Money and although it is an exercise to learn skills, I would eventually want to use it to manage my finances (provided its not too crap!)
This why I thought a fully blown database would be overkill.