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/17/2014 5:29 PM
 

I am looking for an example of how to add communicate in a modified Stored Procedure within a DNN program, my need store-admin/pageid/productadmin/productid/0 but any program ok. 

I have the sql that testing works and it bypasses the insert of adding the record.

How do I tell DNN to stop the add record and give a message to the user?

The sql is in direct sql mode:

       if 'ContractCellPhoneMktPlx_02' not in (select ModelNumber from Store_Products)

       BEGIN

       INSERT INTO dbo.Store_Products

              (PortalID, CategoryID,  ModelNumber, UnitCost,  ProductWeight, ProductHeight, ProductLength, ProductWidth, SaleStartDate, SaleEndDate, SalePrice, StockQuantity, LowThreshold, HighThreshold, DeliveryTime, PurchasePrice, RoleID, Virtual, VirtualFileID, AllowedDownloads)

              VALUES

              (1, 1, 'ContractCellPhoneMktPlx_02',  1.99, 10.52, 0, 0, 0, 6/15/2014, 6/16/2014, 9.99, 0, 0, 0, 1, 5.99, 1, 0, 0, 0)

      

              SELECT SCOPE_IDENTITY()

       END

       ELSE

       SELECT 'Model Number already in database' as 'error'

But it throws an error if it detects duplicate ModelNumber & ok if no error

Error: Store Admin is currently unavailable. DotNetNuke.Services.Exceptions.ModuleLoadException: Input string was not in a correct format. ---> System.FormatException: ….

Thanks in advance for any help!!!

 
New Post
6/18/2014 4:20 AM
 
you cannot produce messages in stored procedure, sorry. This requires changes in API code, either checking actively for existence of the record first or reacting on error code received from the database.

Cheers from Germany,
Sebastian Leupold

dnnWerk - The DotNetNuke Experts   German Spoken DotNetNuke User Group

Speed up your DNN Websites with TurboDNN
 
New Post
6/18/2014 5:08 AM
 

The problem you have is: The API is expecting an integer from the SP, but in case of an error the procedure returns a string.

You can solve that by returning some value that would not be produced, like -1, and then reacting on that value in the API.

To produce an error inside an SQL statement you should do something like this:

BEGIN TRY
   BEGIN TRANSACTION
   IF 'ContractCellPhoneMktPlx_02' not in (select ModelNumber from Store_Products)
      BEGIN
         INSERT ....
         SELECT SCOPE_IDENTITY()
         COMMIT TRANSACTION
      END
   ELSE
      BEGIN
         RAISERROR('Model Number already in database', 16, 1)
      END
END TRY

BEGIN CATCH
   ROLLBACK TRANSACTION
   DECLARE @ErrorMessage nvarchar(max), @ErrSeverity int
   SELECT @ErrMsg = ERROR_MESSAGE(), @ErrSeverity = ERROR_SEVERITY()
   RAISERROR(@ErrMsg, @ErrSeverity, 1)
END CATCH

Best wishes

Michael


Michael Tobisch
DNN★MVP

dnn-Connect.org - The most vibrant community around the DNN-platform
 
New Post
6/18/2014 5:31 AM
 

Michael,

you don't need a Transaction for a single SQL Statement.

And if you raise an error, I don't see a need to return a record set with error details additionally.

IMO it is easier to check existance of the record in API and skip insert accordingly.


Cheers from Germany,
Sebastian Leupold

dnnWerk - The DotNetNuke Experts   German Spoken DotNetNuke User Group

Speed up your DNN Websites with TurboDNN
 
New Post
6/18/2014 5:43 AM
 
Sebastian,

just an example. I just quickly copied something from my scripts to make it clear, and to demonstrate how to do it in SQL.

Best wishes
Michael

Michael Tobisch
DNN★MVP

dnn-Connect.org - The most vibrant community around the DNN-platform
 
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