user34537
user34537

Reputation:

C# database in a file

How do i create a db file in C#? a friend told me it was in the toolbox and not to use sqlite. I dont see anything that could be it, nor what it is called. google didnt help:(

Upvotes: 7

Views: 24687

Answers (8)

Traummaennlein
Traummaennlein

Reputation: 486

Perhaps you might try Microsoft LocalDB. It is file based but uses a low level SQLExpress Installation to host it.

Upvotes: 1

Kbdavis07
Kbdavis07

Reputation: 1100

You can use

FileDB - A C# database to store files

http://filedb.codeplex.com

There is a MVC Example in the source that allows you to upload files and also has drag and drop support.

It then saves it into just one file in a location that you specified.

Like this:

private string pathDB = @"C:\CMS-MVC\Parts\FileManager\filedb-19055\trunk\MvcTest\Data\MvcData.dat"; 

That one file will store all of your files in that one "container".

Upvotes: 0

Robert
Robert

Reputation: 1

Every database has a file system in some binary format more than likely custom and uses a cache to control the flow of the database(s) lifetime.

If you create a database system, you will need some type of cache because you only want to read from the file if the cache has already released it.

If you have 1000 clients tapping into the same db, you certainly don't want to read/write to the file for each client request, so you want to manage a queue of clients and run it against the cache so that the cache knows not to release the db after its time span for lifetime is reached put to rather update the time span, therefore, not having to reload the file, if disposed and queued again, until the queue referencing the db object is empty.

Creating a well designed cache it used by all rdbms's so that duplicate objects are not created and files are not reloaded if not need be.

Upvotes: 0

eglasius
eglasius

Reputation: 36035

On the Add New Item menu: "Service-based Database" or "Sql Server Database" if it is an asp.net application. I am sure your friend meant it as "create a sql express db file in Visual Studio".

That said, if you wanted to fill an empty database, with tables that correspond to a c# model, you could create a linq2sql model, and use its CreateDatabase to do that for you :)

You might want to check this http://quickstarts.asp.net/QuickStartv20/aspnet/doc/data/vwd.aspx (visual web developer link, but it applies).

For a full/in-depth explanation of how SQL express can be used with a semi file based approach check and its limitations: http://www.databasejournal.com/features/mssql/article.php/3704171/SQL-Server-2005-Express-Edition---Part-8---XCopy-Deployment.htm

Upvotes: 1

Dustman
Dustman

Reputation: 5261

If you are using Visual Studio or Web Developer Express, there are indeed ways to easily create a MS SQLExpress database. Just go to Add New Item... and it should be one of the available file types.

Keep in mind you have to have installed either Microsoft SQL Express Edition (free, as in beer!) or Microsoft SQL (very un-free!, in all senses). If you haven't done this, you don't get the option of creating a database file so easily. If you have got it yet, you can get it here.

As other answerers have mentioned, strictly speaking this is NOT a C# feature. MS SQL and it's derivatives, are database applications, much like Oracle, MySQL, or PostgreSQL. It's just that Microsoft Visual Studio makes using the Microsoft database product very easy by default. Differentiating between C#, Visual Studio, and any database programs will probably get you better answers, faster, no matter where you ask. :)

Upvotes: 0

spender
spender

Reputation: 120528

Could it be...

SQL Server Compact Edition – A lightweight, in-process database engine designed to run on devices and desktops and is geared toward local data storage. Compact Edition includes a subset of SQL Server 2005 data types and shares common elements of the Transact-SQL (T-SQL) language with the data service engines.

Upvotes: 9

TheTXI
TheTXI

Reputation: 37905

You are mistaken. Databases are not developed in C#. Databases are built using a database system such as Oracle, MS SQL Server, MySQL, and numerous others.

Once you build a database using one of the above providers, you can then perform actions on the database using your programming language of choice (in your case C#) to get data out of and put data into it.

Upvotes: -8

Rex M
Rex M

Reputation: 144202

There is no file-based database provider built in to c# or the .NET Framework. There are of course pre-existing connectors for using SQL Server (which includes SQL Express), but if you need a fully functional RDBMS that is file-based, you need to use something like SQLite or Firebird (also a fan of VistaDB, not free or open source but VERY solid and pretty affordable).

Upvotes: 4

Related Questions