Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Portable database for C# [closed]

I know that this may seem as a question that was already asked, but I tried the solutions out there already.

I am building a program with C# and I need to save data in a way that every client has his own fresh (dynamic path) to his db. What can I do so users won't need to install extra things, but just .NET framework?

I heard about SQLite, but I didn't really get it working.

like image 654
funerr Avatar asked Sep 14 '11 17:09

funerr


2 Answers

Sql Server CE. It runs in-process and you can deploy all required assemblies with your application. See this article:

How to: Deploy a SQL Server Compact 3.5 Database with an Application

Update: Adding some other SQL Server CE related links that I have found helpful:

  • SQL Server Compact “Private Deployment” on desktop–an overview

  • Using SQL Server Compact 4.0 with Desktop Private Deployment and a Setup project (MSI) (part 2)

  • Privately Deploying SQL Server Compact with the ADO.NET Entity Provider

like image 117
mservidio Avatar answered Sep 20 '22 15:09

mservidio


Download the SQLite .NET data provider here and then reference System.Data.SQLite.dll from within your application. The following example should work right off the bat.

using (var connection = new SQLiteConnection("Data Source=yourfile.db;Version=3;"))
using (var command = connection.CreateCommand())
{
  connection.Open();
  command.CommandText = "select name from from sqlite_master";
  using (var reader = command.ExecuteReader())
  {
    while (reader.Read())
    {
      Console.WriteLine(Convert.String(reader["name"]));
    }
  }
}

Of course all it does is list the tables in the specified file. If the file does not exist then it will be created automatically and naturally there will not be any tables in it. But, at the very least it should work.

like image 37
Brian Gideon Avatar answered Sep 17 '22 15:09

Brian Gideon