Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Error Handling issue

Author  Topic 

shafiqkr
Starting Member

7 Posts

Posted - 2011-11-03 : 00:19:40
HI all,
i want to write log of error occured in stored Procedure,how i can write down SP For that.Here is my code.
string ErrorMessage = "";
// create db
Database db = DatabaseFactory.CreateDatabase();

DbCommand dbCommand = db.GetStoredProcCommand("usp_be_DeleteCityData");
db.AddInParameter(dbCommand, "@CITYID", DbType.Int64, this.CITYID);
db.AddOutParameter(dbCommand, "@ErrorMessage", DbType.String, 150);
int iResult = db.ExecuteNonQuery(dbCommand);
if (iResult > 0) //If Any record is updated in Database then return True Else Return False;
return true;
else
{
Logger.Write(ErrorMessage);
return false;
}
Incase of delete how i ll write an sp which ll output @ErrorMessage with error??

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-03 : 04:26:59
one way is to raise error message from sp and show it here. Other way is to return just status from sp as per error. capture the status code here and show messag as per that code as defined in application

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -