我正在使用以下代码以编程方式创建sql server ce数据库文件。我用的是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();
}
}
我想改进上面的代码。我的问题如下:
-
此方法包含在受保护的类中。我希望直接调用这些方法,而不创建此类的实例。建议一个没有开销的方法。
-
尽管我路过一个
布尔
以确定用户是否要加密文件,但不在连接字符串行中使用。我没有关注加密需要包含哪些其他参数以及如何包含加密算法。
-
我想用最少的开销包括异常处理。我想包括“
使用
,但不遵循如何使用此修改上述代码。