2013-09-10 40 views
0

我是全新的。我正在閱讀一本書並教我自己的C#。我正在讀頭書之一。我剛剛創建了一個聯繫人數據庫程序。我讓SQL數據庫將它放在一個表單上執行所有步驟。當我去運行該程序時,我得到這個視圖源打印?SQL Server CE數據庫升級3.5至4.0 C#

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 

namespace WindowsFormsApplication1 { 
    public partial class Form1 : Form { 
     public Form1() { 
      InitializeComponent(); 
     } 

     private void pictureBox1_Click(object sender, EventArgs e) { 
      MessageBox.Show("Contact List 1.0. \nWritten by: Greg Amero", "About"); 
     } 

     private void peopleBindingNavigatorSaveItem_Click(object sender, EventArgs e) { 
      this.Validate(); 
      this.peopleBindingSource.EndEdit(); 
      this.tableAdapterManager.UpdateAll(this.contactDBDataSet); 
     } 

     private void Form1_Load(object sender, EventArgs e) { 
      // TODO: This line of code loads data into the 'contactDBDataSet.People' table. You can move, or remove it, as needed. 
      this.peopleTableAdapter.Fill(this.contactDBDataSet.People); 
     } 
    } 
} 

this.peopleTableAdapter.Fill(this.contactDBDataSet.People);我得到一個錯誤味精說

SqlCelnvaliddatabase格式的例外是未處理的。
數據庫文件已由早期版本的SQL Server Compact創建。請使用SqlCeEngine.Upgrade()方法升級。 我使用視覺2010

得到上述錯誤。如果我使用Visual 2012表示它工作正常,我想它是與他們逃跑的的SQL Server CE版本。我已經安裝了SQL Server CE 3.5,4.0等,但還是不行。請幫助..

格雷格

+1

你說它適用於'Visual 2012 express',什麼版本的**不能在它的工作? –

+0

版本2010抱歉忘了補充一點 – user160605

回答

0

使用下面的代碼,以3.5文件升級SQL Server精簡版本4.0。

public static void Upgrade(string fileName, string password) 
{ 
    if (String.IsNullOrEmpty(fileName) || password == null) 
     throw new Exception("Unable to create connection string because filename or password was not defined"); 

    try 
    { 
     var connectionString = string.Format(@"Data source={0};Password={1}", fileName, password); 
     var engine = new SqlCeEngine(connectionString); 
     engine.Upgrade(); 
    } 
    catch (Exception ex) 
    { 
     throw (ex); 
    } 
}