我试图找出如何在C#中运行脚本来为SQL Server CE数据库创建表和数据。当ExecutingNonQuery
关闭命令时,我收到以下错误:
解析查询时出错。 [令牌行号= 1,令牌行偏移= 1,令牌错误=使用]
代码:
public static void CreateDatabase()
{
string connStr = "Data Source='C:\\DataBases/MyDatabase.sdf'; LCID=1033; Case Sensitive = TRUE";
if (File.Exists(@"C:\\DataBases\MyDatabase.sdf"))
File.Delete(@"C:\\Databases\MyDatabase.sdf");
SqlCeEngine engine = new SqlCeEngine(connStr);
engine.CreateDatabase();
string originalDatabaseScriptFile = Helpers.Instance.GetAppPath() + "ApplicationHelpers\\MyDatabase.sql";
//run script
FileInfo file = new FileInfo(originalDatabaseScriptFile);
string script = file.OpenText().ReadToEnd();
SqlCeConnection sqlCeConnection = new SqlCeConnection(connStr);
sqlCeConnection.Open();
SqlCeCommand ceCommand = new SqlCeCommand(script, sqlCeConnection);
ceCommand.ExecuteNonQuery(); //Get error here
engine.Dispose();
}
我使用的脚本适用于SQL Server Express(.mdf
),但我想用于SQL Server CE(.sdf
)
有什么可能出错的建议吗?谢谢你的任何建议。