over 7 years ago
The System.Data namespace does not provide an interface for creating databases. This is not a big problem for traditional databases, but it can impose 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:
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 secondmost 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 its handy having the CreateDatabase API right there in my intellisense options.
The third most elegant way, is the SqlCe way. The API is fairly straight forward, and its not too hard to discover the SqlCeEngine object.
My least favorite way it 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?