Skip to content
Sam Saffron

Writing about software, performance, Ruby, Discourse, and technology.

  • Discourse
  • Ruby
  • MiniProfiler
  • SQL
  • AI

Keep it simple

Sam Saffron2 min read

The System.Data namespace does not provide an interface for creating databases. This is not a big problem for traditional databases, but it can pose a problem for the embedded ones.

Here is the round up of how the various dev teams went about solving the problem of creating a database from scratch

The VistaDb way:

VistaDBConnection cnn = new VistaDBConnection("");
VistaDBCommand cmd = cnn.CreateCommand();
cmd.CommandText = "create database test";
cmd.ExecuteNonQuery();

The Firebird way:

FbConnection.CreateDatabase("Database=firebird.db;ServerType=1;User=SYSDBA;Password=password");

The SqlCe way:

SqlCeEngine engine = new SqlCeEngine("Data Source='test.sdf';");
engine.CreateDatabase();

The Sqlite way:

// Do nothing, Connection.Open will create a database if it does not exist.

I think the most elegant way, is the way Sqlite creates databases. Less API calls for me to learn makes me happier.

The second-most elegant way is the Firebird way. Exploring the Connection object is one of the first things you do when dealing with a db provider, so it's handy having the CreateDatabase API right there in my intellisense options.

The third most elegant way, is the SqlCe way. The API is fairly straightforward, and it's not too hard to discover the SqlCeEngine object.

My least favorite way is the VistaDb way. The only way to figure this one out is to read through documentation. Also, I am left thinking, what do I do with these connection and command objects, do I need to dispose them?

Updated February 22, 2019

The conversation

Open in Discuss โ†—

Have a thought or a question? Join the discussion below with your community account.