I created a *.sdf file with password protected using Visual Studio, worked fine. I insert some data and I tried read using Visual Studio SQL editor, but when I went to the C # code that did not work.
I tried the following:
using System;
using System.Data.SqlServerCe;
class Program
{
static void Main(string[] args)
{
var conStr = @"data source=C:\path\db.sdf; password=<...>";
SqlCeConnection con = new SqlCeConnection(conStr);
con.Open();
SqlCeCommand cmd = con.CreateCommand();
cmd.CommandText = "select * from Cookies";
cmd.CommandType = System.Data.CommandType.TableDirect;
cmd.Connection = con;
SqlCeDataReader result = cmd.ExecuteReader();
//...
con.Close();
}
}
I getting the following error:
The specified table does not exist. [ select * from Cookies ]
The table structure

This returns false. Someone can point my mistake?
Thanks in advance.
Your problem is that you’re specifying
System.Data.CommandType.TableDirect.When you change your code to use the following, you’ll avoid the error you’re seeing.
You can even exclude setting the
CommandTypeproperty, asTextis the default.TableDirectis an OLEDB legacy command type. Don’t use it unless your command is only a table or view name. Internally, the command object will construct aSELECT * FROMstatement, selecting all fields and all records from the specified table or view.