繁体   English   中英

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

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

我是新手 我正在看书并教自己的C#。 我正在读HEAD FIRST书之一。 我刚刚创建了一个联系数据库程序。 我使SQL数据库将其放在表单上完成了所有步骤。 当我去运行程序时,我得到了这个视图源打印?

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()方法升级。 我使用Visual 2010收到上述错误

如果我使用Visual 2012 Express,它可以正常工作,并且我认为它与它们所运行的SQL Server CE版本有关。 我已经安装了SQL Server CE 3.5、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