views:

20

answers:

2

how to connect Sqlcompact via. OleDbConnection

my code:

        string strConn = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5; Data Source=C:\\newservice\\UserDataBase\\demo1.sdf;Password=MyPassword";
        conn = new OleDbConnection(strConn);
        conn.Open();
        DataTable dtTable = new DataTable("Record");
        OleDbDataAdapter ada = new OleDbDataAdapter("select * from demo", conn);
        ada.Fill(dtTable);
        conn.Close();

i have got this error:

Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.

how to solve this. wats the problem over here...?

A: 

I think the format of your connection string is a little off. Try:

string strConn = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5; 
                  Data Source=C:\\newservice\\UserDataBase\\demo1.sdf;
                  SSCE:Database Password='MyPassword';";
Justin Niessner
A: 

You should probably use the SQLCeConnection Class for this.

string connStr = "Data Source = Test.sdf; Password = <password>";

 SqlCeConnection conn = null;

try {
   conn = new SqlCeConnection(connStr);
   conn.Open();

  SqlCeCommand cmd = conn.CreateCommand();
  cmd.CommandText = "SQL HERE";

  //Change as needed
  cmd.ExecuteNonQuery();

catch {
finally {
  conn.Close();
Tony Abrams