In my UWP app, I've got an async method (event handler) that calls another async method, which attempts to insert a record into a database.
I'm getting an exception in the insertion attempt, and am trying to sherlock why it's happening. So I put a breakpoint in the InsertMapRecord() method, on the first "using" line:
using (SqliteConnection conn = new SqliteConnection(connStr))
When I reach that breakpoint, I hit F10, but instead of taking me to the next line in the Insert method, it takes me to this line in btnCre8NewMap_Click(), the event handler (which has already been hit, you would think, for the previous line to have been reached):
InsertMapRecord(mapName, mapNotes, defaultZoomLevel);
I then hit F11, in an attempt to return to the InsertMapRecord() method, but instead I end up at App.g.i.cs, on this line:
#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException += (sender, e) =>
{
if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
};
#endif
...with "global::System.Diagnostics.Debugger.Break()" highlighted, and then with this exception message:
The full methods are below
private async void btnCre8NewMap_Click(object sender, RoutedEventArgs e)
{
try
{
string mapName = string.Empty;
string mapNotes = string.Empty;
int defaultZoomLevel = 1;
ClearLocations();
// Popul8 the cmbx
for (int i = 1; i < 20; i++)
{
cmbxCre8MapZoomLevels.Items.Add(i.ToString());
}
ContentDialogResult result = await cntDlgCre8Map.ShowAsync();
if (result == ContentDialogResult.Primary)
{
mapName = txtbxMapName.Text;
mapNotes = txtbxMapNotes.Text;
defaultZoomLevel = cmbxCre8MapZoomLevels.SelectedIndex + 1;
InsertMapRecord(mapName, mapNotes, defaultZoomLevel);
}
// else do nothing (don't save)
}
catch (Exception ex)
{
MessageDialog exceptionMsgDlg = new MessageDialog(ex.Message, "btnCre8NewMap_Click");
await exceptionMsgDlg.ShowAsync();
}
}
private async void InsertMapRecord(string mapName, string mapNotes, int preferredZoomLevel)
{
path = folder.Path;
connStr = string.Format(connStrBase, path);
try
{
using (SqliteConnection conn = new SqliteConnection(connStr))
{
String query = "INSERT INTO dbo.CartographerMain " +
"(MapName, MapNotes, PreferredZoomLevel) " +
"VALUES (@MapName, @MapNotes, @PreferredZoomLevel)";
using (SqliteCommand cmd = new SqliteCommand(query, conn))
{
cmd.Parameters.AddWithValue("@MapName", mapName);
cmd.Parameters.AddWithValue("@MapNotes", mapNotes);
cmd.Parameters.AddWithValue("@PreferredZoomLevel", preferredZoomLevel);
conn.Open();
int result = cmd.ExecuteNonQuery();
if (result < 0)
{
MessageDialog dialog = new MessageDialog("Error inserting data into CartographerMain");
await dialog.ShowAsync();
}
}
}
}
catch (SqliteException sqlex)
{
MessageDialog dialog = new MessageDialog(sqlex.Message, "InsertMapRecord");
await dialog.ShowAsync();
}
}