1

Solution Explorer is shown in this imageHow can i connect with SQL Compact server database for window CE devices. I have tired it with a simple code.Window CE should connect to the SQL compact server but i am novice user for this technology .This is error on device

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

namespace SQLCompactConnectivity
{
    public partial class Form1 : Form
    {
        //public SqlCeConnection con = new SqlCeConnection(@"Data Source=C:\Users\Administrator\Documents\Users.sdf");

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            String query = "Select * from Instrument";
            String conString = @"Data Source =\Program Files\SQLCompactConnectivity\Data\Music.sdf";
            SqlCeConnection con = new SqlCeConnection(conString);
            SqlCeCommand cmd = new SqlCeCommand(query, con);
            con.Open();
            try
            {
                SqlCeDataReader rdr = cmd.ExecuteReader();
                try
                {
                    while (rdr.Read())
                    {
                        this.label1.Text += string.Format("\r\n ID: {0} Name: {1}", rdr[0].ToString(), rdr[1].ToString());
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    rdr.Close();
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }
        }
    }
} 
  • Code looks ok - is the database valid? Is the table there with the given keys? The fact that this error box appears instead of your message box indicates the error is somewhere else. Are you sure this occurs when you comment out the database access code? Have you shipped all required DLLs to use SQLCE? Try debugging setting a breakpoint - on which line does the error occur? – Thorsten Dittmar Jul 21 '16 at 08:38
  • Yes i have added all the required DLLs but still its showing the same error. The error wasn't appear when a run it on emulator. It only shown on the device. – Salman Aslam Jul 21 '16 at 08:42
  • What about my other questions? And what keeps you from debugging on the device? – Thorsten Dittmar Jul 21 '16 at 08:56
  • this.label1.Text += string.Format("\r\n ID: {0} Name: {1}", rdr[0].ToString(), rdr[1].ToString()); The error displays on this line when it tries yo execute it. – Salman Aslam Jul 21 '16 at 09:20

1 Answers1

2

After some R & D i found the answer of this question. The Error means that DLL is not compatible with the device. SQL Compact service pack 1 don't support this. The solution for this problem is to [install SQL Compact service pack 2]1 with Visual Studio 2008. The file is at C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v3.5\Devices\System.Data.SqlServerCe.dll . So Now Remove your previous System.Data.SqlServerCe.dll from reference and add service pack 2 DLL file e.g System.Data.SqlServerCe.dll. I hope this will work for all of you.