views:

33

answers:

1

Hi everyone.. i've been looking for a solution for weeks now. yet still failed..i have stored procedure that was called using in ruby on rails..in that stored proc i have validations and thrown using raiserror.

ex. raiserror("StartDate must be less than EndDate")

in my ruby on rails controller

def save begin M.find_by_sql "EXEC spTestProc '3/15/2010', '3/1/2010'" rescue Exception => e render :js => alert(e.message); end

but instead i get the error message "StartDate must be less than EndDate", I got this error message "DBI::DatabaseError: 37000 (50000) [Microsoft][ODBC SQL Server Driver][SQL Server]StartDate must be less than EndDate..: Exec spTestProc '3/15/2010', '3/1/2010'"

I need to display the error message thrown by my stored proc, but i got some additional message that I dont like to display like "DBI::DatabaseError...etc." how can I do this?

thanks.

A: 

Use regular expression to remove the unwanted text.

e.message.gsub(/(^.*SQL Server\])|(: Exec spTestProc.*$)/i, '')
# this will return StartDate must be less than EndDate..
KandadaBoggu
thanks.. i'll try this.
Jett
but is there no built in function in the Exception class where it would just get the actual errors? like in asp.net, it gets the actual error message. thanks
Jett
It is quite likely that ASP.net is doing this step for you.
KandadaBoggu
thanks! it works!
Jett