views:

95

answers:

3

Need example how to create new local database and a connection string, if possible with a using statement.

There should be 1 table and the data that I want to put in there are unique words length 2-50 lowercase characters, and thy can contain "a-zõäöüšž", ordered by ascending.

There are 2 actions I want to do with that:

  1. Put HashSet of string called words in
  2. Get HashSet of string called words that are specific length

Optionally, I could use an example how to reduce amount of answers given by Get, by telling what letter x must be or what it can not be in a specific location within length of word.

Edit Found my answer by Google.

A: 

you can do all using code, but I would recommend that you ship at least one empty SQL 2008 Express database (mdf file) in your program.

and use the normal Connection String

I did stop shipping SQL Express and only use SQLite now. It's fast and fantastic to use as settings keeper and much more, and I stop having problems in installing this and that on client side to support MS SQL stuff.

I use this on both windows and web apps.

balexandre
Really don't like this advice (to ship an empty MDF) - but I'm not sure I'm qualified to downvote (in terms of knowing best as opposed to anything else)
Murph
How can you create a Database then?? what type? Oracle? MS? SQLite would be the best option, but u need to ship your product with the correct dll's! Please rephrase your question!
balexandre
Erm, providing a database engine is entirely different to shipping a blank database. Yes, in order to use any database you have to provide the appropriate runtime. If you want to avoid an install then I won't dispute that SQLite is an excellent solution and MS SQL CE can also be shipped as .DLLs as part of an application. But I can't see how shipping a *data file* will address the problem.
Murph
A: 

I am not sure I understand your question but you can use SQL Server Compact Edition (SQL ServerCE) as a local database.
You can deal with it as if you are using SQL Server but with the namespace SqlServerCe instead of SqlClient.

sh_kamalh
A: 

In terms of creating databases and schemas from code (C# and MS SQL Server), I have sample code here:

http://stackoverflow.com/questions/1715691/how-to-create-embedded-sql-2008-database-file-if-it-doesnt-exist/1716021#1716021

Murph
Most useful answer.
Margus