简体   繁体   English

SQL Server CE数据库升级3.5到4.0 C#

[英]SQL Server CE database upgrade 3.5 to 4.0 C#

I'm totally new. 我是新手 I'm following a book and teaching my self C#. 我正在看书并教自己的C#。 I'm reading one of the HEAD FIRST books. 我正在读HEAD FIRST书之一。 I just created a contact data base program. 我刚刚创建了一个联系数据库程序。 I made the SQL database placed it on a form did all the steps. 我使SQL数据库将其放在表单上完成了所有步骤。 And when I go to run the program I get this view source print? 当我去运行程序时,我得到了这个视图源打印?

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);
        }
    }
}

At the this.peopleTableAdapter.Fill(this.contactDBDataSet.People); this.peopleTableAdapter.Fill(this.contactDBDataSet.People); I get an error msg saying 我收到一条错误消息,说

SqlCelnvaliddatabase format exception was unhandled. SqlCelnvaliddatabase格式异常未处理。
The database file has been created by an earlier version of SQL Server Compact. 该数据库文件是由早期版本的SQL Server Compact创建的。 Please upgrade using SqlCeEngine.Upgrade() method. 请使用SqlCeEngine.Upgrade()方法升级。 I get the above error using visual 2010 我使用Visual 2010收到上述错误

If I use Visual 2012 express it works fine and I'm thinking it has something to do with the SQL Server CE versions they run off of. 如果我使用Visual 2012 Express,它可以正常工作,并且我认为它与它们所运行的SQL Server CE版本有关。 I've installed SQL Server CE 3.5, 4.0 , etc but still not work.. Please help.. 我已经安装了SQL Server CE 3.5、4.0等,但仍然无法正常工作..请帮助..

Greg 格雷格

Use following code to upgrade SQL Server Compact version 3.5 files to 4.0. 使用以下代码将SQL Server Compact 3.5版文件升级到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);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM