Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get SQL server 2008r2 to show me the Errors?

Tags:

I am running an Insert script that is supposed to insert 13,381 rows into a blank DB from SSMS. Its telling my "Query completed with errors" and is only inserting 13357 rows.

Nothing is showing up in the Error list. How do I locate the mistakes in the script?

Thank you!

like image 959
Chris Chadwick Avatar asked Dec 03 '10 16:12

Chris Chadwick


People also ask

How do I view SQL Server errors?

View the SQL Server error log by using SQL Server Management Studio or any text editor. For more information about how to view the error log, see Open Log File Viewer. By default, the error log is located at Program Files\Microsoft SQL Server\MSSQL. n \MSSQL\LOG\ERRORLOG and ERRORLOG.

Which SQL Server logs shows informational and error events?

The error log contains informational messages, warnings, and information about critical events. The error log also contains information about user-generated messages and auditing information such as logon events (success and failure). The error log is a valuable data point for SQL Server administrators.

How do I create an error log in SQL Server?

In Object Explorer, expand the instance of SQL Server, expand Management, right-click SQL Server Logs, and then click Configure. In the Configure SQL Server Error Logs dialog box, choose from the following options. Check to limit the number of error logs created before they are recycled.

How do I get to SQL Activity Monitor?

Right-click on the top-level object for a SQL Server connection, and select Activity Monitor.


1 Answers

try this:

begin try      --your inserts here  end try begin catch     --returns the complete original error message as a result set     SELECT          ERROR_NUMBER() AS ErrorNumber         ,ERROR_SEVERITY() AS ErrorSeverity         ,ERROR_STATE() AS ErrorState         ,ERROR_PROCEDURE() AS ErrorProcedure         ,ERROR_LINE() AS ErrorLine         ,ERROR_MESSAGE() AS ErrorMessage      --will return the complete original error message as an error message     DECLARE @ErrorMessage nvarchar(400), @ErrorNumber int, @ErrorSeverity int, @ErrorState int, @ErrorLine int     SELECT @ErrorMessage = N'Error %d, Line %d, Message: '+ERROR_MESSAGE(),@ErrorNumber = ERROR_NUMBER(),@ErrorSeverity = ERROR_SEVERITY(),@ErrorState = ERROR_STATE(),@ErrorLine = ERROR_LINE()     RAISERROR (@ErrorMessage, @ErrorSeverity, @ErrorState, @ErrorNumber,@ErrorLine) end catch 
like image 71
KM. Avatar answered Oct 10 '22 22:10

KM.