Create .mdf/.sdf database dynamically

后端 未结 7 905
萌比男神i
萌比男神i 2020-12-29 11:21

How can I with \"code\" create a new .mdf/.sdf database?

I\'ve tried this: http://support.microsoft.com/kb/307283

All it does is fail on the ConnectionString

7条回答
  •  攒了一身酷
    2020-12-29 12:15

    Create .sdf database

    using System.Data.SqlServerCe;
    using System.IO;
      string folderPath="D:\\Compact_DB"
      string connectionString;
      string fileName =folderPath+"\\School.sdf";
      string password = "12345";
    
      if (File.Exists(fileName))
      {
        File.Delete(fileName);
      }
    
      connectionString = string.Format("DataSource=\"{0}\"; Password='{1}'",    fileName, password);
      SqlCeEngine obj_ceEngine = new SqlCeEngine(connectionString);
      obj_ceEngine.CreateDatabase();
    

提交回复
热议问题