0

I have been at this for a few stressful hours and have given up on trying to find a question answered or problem solved for this particular approach I had in mind.

Thing is, I have been given a quite simple task to complete for a job application, but ran into a wall just at the end.

I am to develop an ASP.NET c# web application that shows a GridView with all entries in a SQL Server database table called Tasks which looks like this:

ID int IDENTITY(1,1) PRIMARY KEY, 
Title nvarchar(50) not null, 
DateOpened datetime not null, 
Status bit not null DEFAULT (0) --> opened/closed, 
DateClosed datetime null, 
Description nvarchar(500) null 

I will add the sql needed to understand better it's just I don't have it right now. Also the code you might think is most helpful to avoid a mile long question with lots of copy-pasted code. I didn't wait for it to become available just because I think the code itself would help little to nothing.

I am looking for a way to write an entry to the SQL Server Log File after a user attempts to insert a new Task with the same name AND status as an already existing one.

Basically, if there is an entry in the table like this:

Title 1, opened

and there is another one named Title 1 with status opened being insert into Tasks, the user should be alerted of the attempt, and it should be logged into SQL Server Log File.

I've never done such a thing, so I assume it should be somehow done from the Default.aspx.cs file inside the ValidateNewTask(Task t) method, where I run a foreach loop against all fetched entries, and if a "hit" appears, redirect the user to an error page or maybe keep it all on the same page with an error label since it's not that severe (like a RequiredFieldValidator would do), and THEN access the log to write the new entry of an error occurred.

Am I missing something that's right in front of me, or is this just not ever done (like this/ or at all)?

3
  • You cannot write into the SQL Server (transaction) log file directly - SQL Server uses that internally, only. Also, the SQL Server transaction log file is for handling transaction activities - it's not a log file to dump warnings or error into... Commented Feb 14, 2015 at 10:04
  • Maybe you misunderstood the requirements? Did they ask you to explicitly use the "SQL Server Log File"? Commented Feb 14, 2015 at 10:12
  • Tank you for your comment marc_s, I did expect something like that to be said, its just that an experienced software engineer stated in this assignment that the attempt of such an entry should alert the user of an error during validation/insert into sql, AND to write that attempt to the sql server log file. Should I use a trigger on INSERT and then lets say...simulate stuff or some other workaround with for instance a RAISERROR sql command inside the trigger? Or just dump the situation to a log the way it's usually done? Commented Feb 14, 2015 at 10:13

1 Answer 1

1

You can use RAISERROR ... WITH LOG to raise an error (the user will receive a SqlException) and write it to the SQL Server log file but this is not something I would recommend. The SQL Server log file is for SQL Server, if your application needs a log file I would create something separate and independent. Note the comments in the MSDN documentation about being SA or having ALTER TRACE to use WITH LOG.

Sign up to request clarification or add additional context in comments.

1 Comment

I get that the SQL Server log isn't meant to work like that, this info can help to do a good job about the app itself, given I do the task using the classic best practice, and just comment that part in-code or in the second interview about why i didn't use sloppy workarounds and/or unused practices. The interviewer is quite the German style OCD programmer who would want the result to be maximum performance oriented using best practices. Thank you all!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.