DNN Blog Module not saving posts properly - dotnetnuke

The DNN Blog is not saving the posts anymore. I can see the latest post in the Manage Content/Data, and it says it is visible but once you are out of the edit mode it is not there. Now, when I click on the save the alert comes up that says ***Had an error talking to the server (400)), Bad request, Could not find stored procedure ‘toSIC_EAV_ChangeLogAdd’.
What I did I updated 2sxc App and the Content module to 9.32.0, and had no luck.
Can anyone point me in the right direction, please?
DNN Version v. 09.01.01 (129)

We ran this stored procedure, which we got from the module creator's git hub, to fix our problem:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[ToSIC_EAV_ChangeLogAdd]
-- Add the parameters for the stored procedure here
#User nvarchar(255) = null
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
--SET NOCOUNT ON;
-- Insert statements for procedure here
INSERT INTO [dbo].[ToSIC_EAV_ChangeLog] ([Timestamp] ,[User])
VALUES (GetDate(), #user)
DECLARE #ChangeID int
SET #ChangeID = scope_identity()
EXEC ToSIC_EAV_ChangeLogSet #ChangeID
SELECT *
FROM [dbo].[ToSIC_EAV_ChangeLog]
WHERE [ChangeID] = #ChangeID
END
GO

Related

With a DACPAC, how can I rename a column when there is a trigger on the table?

I'm trying to rename columns in a table for which there is a trigger. I've used SQL > Refactor > Rename to rename the column. And the trigger file also gets updated. However, when I publish, I get this:
Procedure TR_accrual_Accrual_Update, Line 134 Invalid column name
'MinHoursRule'.
That's the old column name. I'm assuming the publish is updating the table first, and sees that the current/old trigger still has the old column name.
Is it possible to rename a column, update the trigger, and publish?
The only solution I can really think of is to do this:
Delete the triggers and publish
Rename the columns
Add the triggers again
Publish
This is what I did as a work-around:
Add the new columns
Leave the old columns
Have the trigger use both sets of columns
Publish/deploy to prod soon
Remove the old columns
Publish/deploy to prod later
So, instead of renaming, I just created new columns, and then eventually deleted the old ones.
Yuck. But it worked.
Note: In our C# domain models, I only reference the new columns.
I guess that you have something wrong with the publish profile settings. You might have something disabled, for example "Do not modify triggers" or something like that. I just created new SSDT project in VS 2019 with following structure:
CREATE TABLE [dbo].[test]
(
[Id] INT ,
b int
)
GO
CREATE TRIGGER [dbo].[Trigger_test]
ON [dbo].[test]
FOR DELETE, INSERT, UPDATE
AS
BEGIN
SET NoCount ON
insert into test2 select b from inserted
END
GO
CREATE TABLE [dbo].[test2]
(
a int
)
GO
Published the project with default settings to the new database and made single insert to the dbo.test table. Made sure that there is record in dbo.test2 table. After that I re-factored dbo.test.b column to dbo.test.a then published again and everything worked. This is generated script:
/*
Deployment script for trg_test
This code was generated by a tool.
Changes to this file may cause incorrect behavior and will be lost if
the code is regenerated.
*/
GO
SET ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS, ARITHABORT, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER ON;
SET NUMERIC_ROUNDABORT OFF;
GO
:setvar DatabaseName "trg_test"
:setvar DefaultFilePrefix "trg_test"
:setvar DefaultDataPath ""
:setvar DefaultLogPath ""
GO
:on error exit
GO
/*
Detect SQLCMD mode and disable script execution if SQLCMD mode is not supported.
To re-enable the script after enabling SQLCMD mode, execute the following:
SET NOEXEC OFF;
*/
:setvar __IsSqlCmdEnabled "True"
GO
IF N'$(__IsSqlCmdEnabled)' NOT LIKE N'True'
BEGIN
PRINT N'SQLCMD mode must be enabled to successfully execute this script.';
SET NOEXEC ON;
END
GO
USE [$(DatabaseName)];
GO
PRINT N'The following operation was generated from a refactoring log file 80d0e5de-e188-465e-b83c-18f38a1cec98';
PRINT N'Rename [dbo].[test].[b] to a';
GO
EXECUTE sp_rename #objname = N'[dbo].[test].[b]', #newname = N'a', #objtype = N'COLUMN';
GO
PRINT N'Altering Trigger [dbo].[Trigger_test]...';
GO
ALTER TRIGGER [dbo].[Trigger_test]
ON [dbo].[test]
FOR DELETE, INSERT, UPDATE
AS
BEGIN
SET NoCount ON
insert into test2 select a from inserted
END
GO
-- Refactoring step to update target server with deployed transaction logs
IF OBJECT_ID(N'dbo.__RefactorLog') IS NULL
BEGIN
CREATE TABLE [dbo].[__RefactorLog] (OperationKey UNIQUEIDENTIFIER NOT NULL PRIMARY KEY)
EXEC sp_addextendedproperty N'microsoft_database_tools_support', N'refactoring log', N'schema', N'dbo', N'table', N'__RefactorLog'
END
GO
IF NOT EXISTS (SELECT OperationKey FROM [dbo].[__RefactorLog] WHERE OperationKey = '80d0e5de-e188-465e-b83c-18f38a1cec98')
INSERT INTO [dbo].[__RefactorLog] (OperationKey) values ('80d0e5de-e188-465e-b83c-18f38a1cec98')
GO
GO
PRINT N'Update complete.';
GO

SQL Server stored procedure - update one table and insert into another table

I've got a stored procedure that is coded similarly to the following:
USE [database]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROC [dbo].[procedure_name]
#record_id int
, #record_value VARCHAR(MAX)
AS
BEGIN
UPDATE dbo.table_1
SET table_1_record_value = #record_value
WHERE table_1_record_int = #record_int
END
BEGIN
INSERT INTO table_2 COLUMNS (table_2_record_id, table_2_record_value) VALUES (#record_id, #record_value)
END
And I'm getting a syntax error. I've never had to write a stored procedure for an application that would accomplish both an UPDATE and an INSERT statement together.
The answer was provided by bbaird in the comments. Removing the BEGIN/END keywords fixed the problem. Thank you!
bbaird's full comment below:
If the procedure isn't created yet, you will need to do CREATE PROCEDURE. 2. The update and insert statements are independent, no need to put them in their own BEGIN...END block unless there is a conditional. 3. COLUMNS in the insert statement might also be throwing things off - it is not necessary so remove it.
The answers of Jake and bbard are correct.
Below the code of your stored procedure:
USE [database]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE OR ALTER PROC [dbo].[procedure_name]
#record_id int
, #record_value VARCHAR(MAX)
AS
BEGIN
UPDATE dbo.table_1
SET table_1_record_value = #record_value
WHERE table_1_record_int = #record_int
INSERT INTO table_2 COLUMNS (table_2_record_id, table_2_record_value)
VALUES (#record_id, #record_value)
END
For documentation of BEGIN and END look here

Stored Procedures and ASP .NET

i created a stored procedure on sql server for updating records,while there it works fine when I insert the required parameters... but when it comes to ASP .NET when I run the application when I press update on ASPX GridView it gives me a Message
"Procedure or function custUPDATE has too many arguments specified."
here is the code for my procedure
alter proc custUPDATE
( #odid int,
#customer_id int,
#priceID int,
#etAMOUNT int,
#amntPaid decimal(18,2),
#od_status varchar(20),
#py_status varchar(20),
#order_date smalldatetime
-- #dummy varchar(30) =null
)
as
begin
set nocount on;
declare #amnt_paid decimal(18,2);
declare #rmn decimal(23,4);
declare #tt money;
select #amnt_paid=eggsOrders.amnt_paid from eggsOrders where od_ID=#odid;
select #rmn= orderVIEW.Remaining from orderVIEW where od_ID=#odid;
select #tt=orderVIEW.Total from orderVIEW where od_ID=#odid;
--select #amnt_paid= amnt_paid from inserted;
if(#amnt_paid=#tt)
begin
update [dbo].[eggsOrders] set customer_ID=#customer_id, price_ID=#priceID, ET_amount=#etAMOUNT, amnt_paid=#amntPaid, Od_status=#od_status, py_status='paid in full', order_date=#order_date where od_ID=#odid;
end
else if(#amnt_paid>0 and #amnt_paid!=#tt)
begin
update [dbo].[eggsOrders] set customer_ID=#customer_id, price_ID=#priceID, ET_amount=#etAMOUNT, amnt_paid=#amntPaid, Od_status=#od_status, py_status='In-Progress', order_date=#order_date where od_ID=#odid
end
else if(#amnt_paid=0 and #rmn =#tt)
begin
update [dbo].[eggsOrders] set customer_ID=#customer_id, price_ID=#priceID, ET_amount=#etAMOUNT, amnt_paid=#amntPaid, Od_status=#od_status, py_status='Payment Pending', order_date=#order_date where od_ID=#odid
end
end
go
what am I doing wrong???
please help
The error is cristal clear: you're passing more parameters to the method than what it expect, causing the error. Review carefully how many parameters are you passing in the call to SP.
I’ve noticed occasionally that ASP.NET will cache the old SPROC in Visual Studio even after a change is made on SQL Server. So for example you changed custUPDATE by adding a parameter, and also added the parameter to your ASP.NET code, but are still receiving the “too many arguemtns specified” error because the old SPROC is being cached.
If this is the case I would try the following:
Change the SPROC name in your ASP.NET page from custUPDATE to [custUPDATE] and then try running it.

Must Declare Scalar variable on creating stored procedure

I am creating first time stored procedure but I don't know why this showing error. I also have many other post but didn't understand if someone can tell what I am doing wrong here.
Stored procedure:
SET ANSI_NULLS ON
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[DeleteOrganization]
#ORG_ID bigint
AS
BEGIN
SET NOCOUNT ON;
delete from Organizations where ORG_ID=#ORGID
delete from Institutes where INS_FK_ORGID=#ORGID
delete from Branches where BRN_ID=#ORGID
END
The variable is declared as #ORG_ID bigint with an underscore but you refer to it without the underscore: #ORGID. Pick one and use it consistently.
This should work:
ALTER PROCEDURE [dbo].[DeleteOrganization]
#ORGID bigint
AS
BEGIN
SET NOCOUNT ON;
DELETE FROM Organizations WHERE ORG_ID = #ORGID
DELETE FROM Institutes WHERE INS_FK_ORGID = #ORGID
DELETE FROM Branches WHERE BRN_ID = #ORGID
END

MS SQL: Suppress return value of stored procedure called in stored procedure

I think I have the same problem as kcrumley describes in the question "Problem calling stored procedure from another stored procedure via classic ASP". However his question does not really include an solution, so I'll give it another shot, adding my own observations:
I have two stored procedures:
CREATE PROCEDURE return_1 AS BEGIN
SET NOCOUNT ON;
SELECT 1
END
CREATE PROCEDURE call_return_1_and_return_2 AS BEGIN
SET NOCOUNT ON;
EXEC return_1
SELECT 2
END
Note that both procedures contain "SET NOCOUNT ON". When I execute "call_return_1_and_return_2" I still get two record sets. First the value 1, then the value 2.
That throws ASP (classic VBScript ASP) off the tracks.
Any hints on how I can suppress the first result set? Why is it there even with NOCOUNT?
Skipping the first record set in ASP is not an option. I need a "database only" solution.
As Matt points out in his comment, neither solution really 'swallow' the first resultset.
I don't know why you'd want this but you can 'swallow' the result of the first exec by using a table variable. It must match the exact amount and type of the result set's columns. Like so:
CREATE PROCEDURE return_1 AS
SET NOCOUNT ON;
SELECT 1
GO
CREATE PROCEDURE call_return_1_and_return_2 AS
SET NOCOUNT ON;
DECLARE #Result TABLE (res int)
insert into #Result EXEC return_1
SELECT 2
GO
Its not the NOCOUNT thats causing this, your stored procedures have a select each so each one is coming in its own result set. This could be avoided by changing your first stored procedure to use output parameters to pass the number 1 back rather than doing a select. The second stored procedure could then examine the output parameter to get the data it needs to run.
Try something like this
CREATE PROCEDURE Proc1
(
#RetVal INT OUTPUT
)
AS
SET NOCOUNT ON
SET #RetVal = 1
CREATE PROCEDURE Proc2
AS
SET NOCOUNT ON
DECLARE #RetVal int
EXEC [dbo].[Proc1]
#RetVal = #RetVal OUTPUT
SELECT #RetVal as N'#RetVal'
Those are not return variables, but output record sets. I guess that as soon as SQL server flushes output to client, you're screwed and can't take it back.
I would solve this by adding a parameter to SP return_1, that would control if return_1 would select records or just do stuff and silently exit.

Resources