CODECUBE VENTURES

SqlCeExceptions

Just a quick code snippet on how to access and display SqlCeExceptions.

please note that SqlCeExceptions can have one or more error at a time ... that's why it actually stored it in the Errors collection. To display it, you need to iterate over that collection and pull out the info that way:

if (File.Exists(LocalDataSourcePath) == false)
{
SqlCeEngine sqlCe = new SqlCeEngine(LocalDataSource);
try
{ 					sqlCe.CreateDatabase();
}
catch (SqlCeException scex)
{
StringBuilder sb = new StringBuilder();
for (int i=0;i<scex.Errors.Count;i++)
{
sb.Append(string.Format("{0}\n----\n",scex.Errors[i].Message));
}
MessageBox.Show(sb.ToString());
return;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
finally
{
sqlCe.Dispose();
}
}

Latest post: Digging Up the First Version of CodeCube

See more in the archives