I am trying to use the sqlException handler, but it is not working. Tried researching and reviewing everything I know. Using Visual Studio 2017 (latest update), Xamarin, .net 4.7, Windows 10 creators updates. I am using the correct package, but it is not recognized. My code is below. I either must be missing something, or am not seeing something, but this should work as intended. The standard Exception works, but the SqlException is not recognized. Please help.
using System;
using System.Data.SqlClient;
using System.Data.SqlClient.SqlException;
namespace MobileWebServices.SqlClientFiles
{
public partial class SqlClient
{
private int GetMaxECMDataID(string tClientNumber, string tClientPassCode, string tFileID)
{
int maxECMDataID = 0;
var tempConnection = GetTempConnection();
try
{
tempConnection.Open();
string SQLString = "SELECT max(ECMDataID) as mECMDataID FROM ECMData WHERE FileId = " + "'" + tFileID + "'" + " and iPadLocation = " +
"'" + tClientNumber + "'" + " and licensePassCode = " + "'" + tClientPassCode + "'";
var sqlcommand = new SqlCommand(SQLString, tempConnection);
maxECMDataID = (int)sqlcommand.ExecuteScalar();
}
catch (SqlException sqlex)
{
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Works as expected on my machine. If you copy the line from the Exception block into the SqlException catch block, you should see output. In my case, I get
The ConnectionString property has not been initialized.