[英]Create SQL Server CE database file programmatically
如何以编程方式创建新的SQL Server Compact数据库文件(.sdf),而无需从中复制现有模板文件?
There is some good info here: Create a SQL Server Compact Edition Database with C# 这里有一些很好的信息: 使用C#创建SQL Server Compact Edition数据库
string connectionString = "DataSource=\"test.sdf\"; Password=\"mypassword\"";
SqlCeEngine en = new SqlCeEngine(connectionString);
en.CreateDatabase();
First, go click on the Browse tab. 首先,单击“浏览”选项卡。 Now navigate to
C:\\Program Files\\Microsoft SQL Server Compact Edition\\v3.1
. 现在导航到
C:\\Program Files\\Microsoft SQL Server Compact Edition\\v3.1
。 Now pick the System.Dadta.SqlServerCe.dll
, click on it, then click on OK to pull in the reference. 现在选择
System.Dadta.SqlServerCe.dll
,单击它,然后单击确定以拉入引用。
Now let's write some code. 现在让我们写一些代码。 First, go to the head of the class, whoops I mean header of your class and let's create a using reference.
首先,去班级的负责人,呐喊我的意思是你的班级的标题,让我们创建一个使用参考。
using System.Data.SqlServerCe;
using System.IO;
string connectionString;
string fileName = "aminescm.sdf";
string password = “aminescm”;
if (File.Exists(fileName))
{
File.Delete(fileName);
}
connectionString = string.Format(
"DataSource=\"{0}\"; Password='{1}'", fileName, password);
SqlCeEngine en = new SqlCeEngine(connectionString);
en.CreateDatabase();
You can find more and more about this, it's really an amazing web site: 你可以找到越来越多的关于这个,它真的是一个惊人的网站:
http://arcanecode.com/arcane-lessons/ http://arcanecode.com/arcane-lessons/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.