Add to Favorites    Make Home Page 6736 Online  
 Language Categories  
 Our Services  

Home » ASP Home » SQL Home » Import the SQL Server error log into a table

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title Import the SQL Server error log into a table
Description To import the SQL Server error log into a table, so that it can be queried
Category ASP » SQL
Hits 362338
Code Select and Copy the Code
CREATE PROC sp_import_errorlog ( @log_name sysname, @log_number Int = 0, @overwrite bit = 0 ) As /************************************************************************************************* Purpose: To import the SQL Server Error Log into a table, so that it can be queried Tested On: SQL Server 2000 Limitation: With Error messages spanning more than one line only the first line Is included In the table Example 1: To import the current Error Log To table myerrorlog EXEC sp_import_errorlog 'myerrorlog' Example 2: To import the current Error Log To table myerrorlog, And overwrite the table 'myerrorlog' if it already exists EXEC sp_import_errorlog 'myerrorlog', @overwrite = 1 Example 3: To import the previous Error Log To table myerrorlog EXEC sp_import_errorlog 'myerrorlog', 1 Example 4: To import the Second previous Error Log To table myerrorlog EXEC sp_import_errorlog 'myerrorlog', 2 *************************************************************************************************/ BEGIN Set NOCOUNT On Declare @sql varchar(500) --Holds To SQL needed To create columns from Error Log If (Select OBJECT_ID(@log_name,'U')) IS NOT NULL BEGIN If @overwrite = 0 BEGIN RAISERROR('Table already exists. Specify another name or pass 1 to @overwrite parameter',18,1) RETURN -1 End Else BEGIN EXEC('DROP TABLE ' + @log_name) End End --Temp table To hold the output of sp_readerrorlog CREATE TABLE #errlog ( err varchar(1000), controw tinyint ) --Populating the temp table using sp_readerrorlog INSERT #errlog EXEC sp_readerrorlog @log_number --This will remove the header from the errolog Set ROWCOUNT 4 DELETE #errlog Set ROWCOUNT 0 Set @sql = 'SELECT CONVERT(DATETIME,Left(err,23)) [Date], SUBSTRING(err,24,10) [spid], Right(err,Len(err) - 33) [Message], controw INTO ' + QUOTENAME(@log_name) + ' FROM #errlog ' + 'WHERE controw = 0' --Creates the table With the columns Date, spid, message And controw EXEC (@sql) --Dropping the temporary table DROP TABLE #errlog Set NOCOUNT OFF Print 'Error log successfully imported to table: ' + @log_name End

Related Source Codes

Script Name Author
ııııııııııııııııııııı VyomWorld
Resistor color code reader A.Chermarajan.
Telephone Directory dhivya
card swapping game (Mini Project) nityanand
simple hangman-pascalsource Seabert
college dirtectory (Mini Project) msridhar
Poll Application John van Meter
ASP Daily Hit Counter. Tejaskumar Gandhi
To avoid null in asp environment using sql Sami
Maklumbalas webmaster
poll John van Meter
EasyASP Template Engine. TjoekBezoer
Basic Calculator using HTML & Javascript. Patrick M. D Souza
What servers support ASP ? VyomWorld
What is ASP? VyomWorld

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2024 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=218


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review