I have this code that calls the stored procedure to 'insert' data to tables in SQL.
using (SqlConnection connection = new SqlConnection(Global_Variables.DBcon))
{
SqlCommand cmd = new SqlCommand("sp_WinApps_Import_ERData", connection);
cmd.CommandType = CommandType.StoredProcedure;
connection.Open();
try
{
cmd.ExecuteNonQuery();
Console.WriteLine("file imported!");
}
catch (SqlException ex)
{
Console.WriteLine("BATCH ID ALREADY EXISTS!" + ex.Message );
}
finally
{
connection.Close();
}
}
but the problem is, it doesn't catch the error in the 'try-catch method' i dont know why but my code is correct.
The Error says: "Violation of UNIQUE KEY constraint 'Cons_BatchID'. Cannot insert duplicate key in object 'dbo.tbl_WinApps_FileHeader'. Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. The statement has been terminated."