Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...How to add communicate in a modified Stored Procedure within a DNN programHow to add communicate in a modified Stored Procedure within a DNN program
Previous
 
Next
New Post
6/18/2014 10:28 AM
 
Michael:

Thanks for your input.

Your last example after the other discussion with Sebastian does not appear now.  Would you please post it again.

Thanks

Lee

 
New Post
6/20/2014 1:50 AM
 

Lee,

sorry for my bad English. I did not post another example, I meant the code above as an example. Sebastian is right of course, you don't need a transaction for a single INSERT statement, I forgot to pull that out. I just mixed the code above with some code of mine, that was Q&D.

When I want to write this a bit cleaner, I would do it like this:

BEGIN TRY
   BEGIN
      INSERT INTO ...
      SELECT SCOPE_IDENTITY()
   END
END TRY

BEGIN CATCH
   DECLARE @ErrMsg nvarchar(max), @ErrSeverity int, @ErrNumber int
   -- Assuming the field 'ModelNumber' has an unique index or is primary key
   SET @ErrNumber = ERROR_NUMBER()
   SET @ErrMsg = 
      CASE
         -- Unique index violation
         WHEN (@ErrNumber = 2601) THEN 'Model Number already in database - Error 2601'
         -- Primary key violation
         WHEN (@ErrNumber = 2627) THEN 'Model Number already in database - Error 2627'
         ELSE ERROR_MESSAGE() + ' - Error ' + LTRIM(RTRIM(CAST(@ErrNumber AS nvarchar(max))))
      END
   SET @ErrSeverity = ERROR_SEVERITY()
   RAISERROR(@ErrMsg, @ErrSeverity, 1)
END CATCH

Of course you have to handle the raised exception from your SQL statement inside you programming code somewhere, normally within constructs like this:

try {
   ...
} catch (Exception ex) {
   Exceptions.ProcessModuleLoadException(this, ex);
}

Best wishes


Michael Tobisch
DNN★MVP

dnn-Connect.org - The most vibrant community around the DNN-platform
 
New Post
6/20/2014 1:55 PM
 

Thanks Michael

Lee

 
Previous
 
Next
HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...How to add communicate in a modified Stored Procedure within a DNN programHow to add communicate in a modified Stored Procedure within a DNN program


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out