简体   繁体   中英

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#. I'm reading one of the HEAD FIRST books. I just created a contact data base program. I made the SQL database placed it on a form did all the steps. 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); I get an error msg saying

SqlCelnvaliddatabase format exception was unhandled.
The database file has been created by an earlier version of SQL Server Compact. Please upgrade using SqlCeEngine.Upgrade() method. I get the above error using 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. I've installed SQL Server CE 3.5, 4.0 , etc but still not work.. Please help..

Greg

Use following code to upgrade SQL Server Compact version 3.5 files to 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);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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