Catching SqlException does not work in my rest API

Adagio_B 25 Reputation points
2023-05-01T08:32:23.5133333+00:00

EDIT: Just delete this question. I currently don't have time to follow up

I'm having an issue, when my rest API code is deployed on our test server. I have the below code. This works fine on my development machine, but when deploying to our test-server and calling this method, all I'm getting is 500 internal error and the log file is not created. If I remove the part where it catches the SqlException, then calling the method works as expected and my log file is correctly created

I have installed the Nuget package System.Data.SqlClient 4.8.5

Does anybody have any idea what I am missing? From what I can tell, the System.Data.SqlClient.dll file on the server is the same as on my development machine

[HttpPut("Proposal/{labelId}/{buildId}/{identId}/{proposalId}")]
		public ResponseOpaqueConstruction AddProposal(int labelId, int buildId, int identId, int proposalId)
		{
			ResponseOpaqueConstruction response = new ResponseOpaqueConstruction();

			try
			{
				using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Temp\TellMeSomething.log", true))
					file.WriteLine(DateTime.Now.ToString("T") + " - Inside try");
			}
			catch (SqlException ex)
			{
				
			}
			catch (Exception ex)
			{
				
			}

			return response;
		}
Developer technologies | Visual Studio | Other
Developer technologies | C#
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.