A couple of things I would change to get this code working.
The connection string properties for SqlCe are a reduced set of those
available for the full .NET framework. Initial Catalog, User ID, don't
show up in the documentation. I'm not sure if it is explicitly
required, but normally, the connection is opened before the command is
created. Also, you need to create a SqlCe... Connection, Command,
etc.. as opposed to a Sql... Connection, Command, etc.
Hope the following helps.
public void Form1_Load(Object sender, EventArgs e) {
string strconn = @"Data Source=XXX.XXX.XXX.XXX, YYYY;Persist Security
Info=True; Password=password";
string strGetEmpls = " SELECT * from emp ";
try {
using (SqlCeConnection conndb = new SqlCeConnection(strconn)) {
conndb.Open();
using (SqlCeCommand cmndb = new SqlCeCommand(strGetEmpls,
conndb)) {
using (SqlCeDataReader rdr = cmndb.ExecuteReader()) {
while (rdr.Read()) {
MessageBox.Show((String)rdr["emp_name"]);
}
}
}
}
} catch (SqlException ex) {
foreach (SqlError err in ex.Errors) {
MessageBox.Show(err.Message);
}
}
}
Good Luck,
fi