I am using following code to create SQL Server CE database file programmatically. I am using C# 2008.
/* Create a new SQL Server CE database file programatically */
protected void CreateDB(string _databaseFileName, bool _encryptFile, string _password)
{
if (File.Exists(_databaseFileName))
MessageBox.Show("A file with this name already exists.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
else
{
string connectionString = string.Format("DataSource=\"{0}\"; Password='{1}'", _databaseFileName, _password);
SqlCeEngine engine = new SqlCeEngine(connectionString);
engine.CreateDatabase();
}
}
I want to improve the above code. My queries are below:
This method is contained in a protected class. I want these methods to be called directly without creating an instance of this class. Suggest a way with no overhead.
Though I am passing a bool to determine whether the user wants to encrypt file or not, but not used in the connection string line. I am not following which other parameter need to be included for encryption and how to include encryption algorithm.
I want to include exception handling with least overhead. I want to include "using", but not following how to modify the above code with this.