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.
Related
I have a stored procedure that returns a string value based on conditions, and it has or 4 parameters. I face challenge in executing the stored procedure and retrieving the result.
I find everywhere that returns results from insert queries from same model. Kindly share your suggestions for this.
This is my stored procedure:
CREATE PROCEDURE [dbo].[sp_test]
(#param1 INT,
#param2 NVARCHAR(100),
#param3 INT,
#param4 NVARCHAR(50))
AS
BEGIN
IF (#param1 = '')
BEGIN
SELECT 'ok' AS output
END
ELSE
SELECT 'not ok' AS output
END
Please suggest how to get this query result using Entity Framework Core 3.0 DbContext.
The error I get when I try using .FromSqlRaw:
FromSqlRaw or FromSqlInterpolated was called with non-composable SQL and with a query composing over it. Consider calling AsEnumerable after the FromSqlRaw or FromSqlInterpolated method to perform the composition on the client side.
Rewrite it as :
CREATE PROCEDURE [dbo].[sp_test](#param1 INT,#param2 NVARCHAR(100),#param3 INT,#param4 NVARCHAR(50), #STR_OUT NVARCHAR(256) OUTPUT)
AS
BEGIN
IF (#param1='')
BEGIN
SET #STR_OUT ='ok';
END
else
SET #STR_OUT = 'not ok';
And read the OUTPUT value of the last parameter.
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
I have a stored procedure called myStoredProcedure in SQL Server 2008 including a code block like this:
...
declare #tempTable table
(
Id int,
Name varchar(100),
Category varchar(50),
Volume int
)
while #startTime<#endTime
begin
insert into #tempTable
EXEC R52_Calculations #param1, #param2, #param3
set #startTime = DATEADD(YEAR,1,#startTime)
end
select * from #tempTable
In this way, the stored procedure is working very well. I can connect to a table to this stored procedure in the SSRS 2008 without any warning or error. However, when I change #tempTable variable into #tempTable like below, I am getting a TimeOut error when I try to connect a table on SSRS 2008 to the updated stored procedure, even though the stored procedure is working very well again in SQL Server.
...
create table #tempTable
(
Id int,
Name varchar(100),
Category varchar(50),
Volume int
)
while #startTime<#endTime
begin
insert into #tempTable
EXEC R52_Calculations #param1, #param2, #param3
set #startTime = DATEADD(YEAR,1,#startTime)
end
select * from #tempTable
This is the error:
Timeout expired. The timeout period elapsed prior to completion of
the operation or the server is not responding. Warning: Null value is
eliminated by an aggregate or other SET operation.
Some more points:
when I remove the "while" loop and do the process only 1 time, there is no error occurring when I use #tempTable.
if I use #temptable (variable one), there is no error occurring at all.
Note that both queries are working fine in SQL Server, the errors are occurring when I try to connect a table on SSRS 2008 to the stored procedure
.
I could not find the reason why #temptable is causing an error. Any clue or help I will appreciate. Thanks.
I want to save a stored procedure which contains errors according to SQL Server.
This is the procedure code:
Create PROCEDURE [Product].[JewelSearch]
#JewelItem bigint,
#JewelType nvarchar(50),
#JewelMate nvarchar(50)
AS
BEGIN
SET NOCOUNT ON;
SELECT *
FROM Product.#JewelType
WHERE Material = #JewelMate OR Item# = #JewelItem;
END
The problem is that I have a Product schema, and I am taking the table name from my main application and saving it in #JewelType and in each search in main application the table name must be changed and each time their will be a different table name in #JewelType.
According to me the query is perfect but SQL Server does not allow me to execute it and save it. Is there a way that I can forcibly save this stored procedure? Hope you understand my question please help me if possible.
If it is SQL Server, something like this should work
Create PROCEDURE [Product].[JewelSearch]
#JewelItem bigint,
#JewelType nvarchar(50),
#JewelMate nvarchar(50),
#SQL nvarchar(max)
AS BEGIN
SET NOCOUNT ON;
SET #SQL = 'Select * From Product.'+#JewelType+' where Material = '+#JewelMate+' OR Item# = '+CAST(#JewelItem as nvarchar(50))+'; '
EXEC(#SQL)
END
This is untested as I am on my Mac, but you get the idea.
If you are going to use this, be aware of the dangers of dynamic SQL in relation to SQL Injection.
SQL Injection with Dynamic SQL - MSDN
I'm trying to call a custom stored procedure in SQL Server 2008 R2 from SSIS in Visual Studio 2012. I wrote and tested the stored procedure in SSMS 2012 and it works as expected.
However, when I try to place it in an OLE DB Command component I receive a Divide by 0 error when I refresh the component or when the SSIS package validates.
Here's the code for the stored procedure:
CREATE PROCEDURE [ldg].[2015HRUpdate(TEST)]
#Employee varchar(20), -- maps to EM.Employee, primary key
#Title varchar(50), -- maps to EM.Title
#PayRate varchar(50) = '0', -- maps to EM.JobCostRate, convert to decimal
-- #Percentage Decimal(19,4) = 0, -- workaround
#OldPayRate Decimal(19,4) = 0, -- used to calculate Employees_SalaryHistory.Custnprcent, convert to decimal
#LaborCategory varchar(50) = '0', -- maps to EM.BillingCategory, convert to small int
#EmployeeDesignation varchar(50), -- maps to EmployeeCustomTabFields.CustEmployeeDesg
#FSLAStatus varchar(50), -- maps to EmployeeCustomTabFields.CustFSLAStatus
#Supervisor varchar(20), -- maps to EM.Supervisor
#SupervisorName varchar(255), -- maps to Employees_SalaryHistory.custSuper
#ModUser nvarchar(20),
#ModDate datetime
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Convert data types to match database data types
declare #JobCostRate decimal(19,4);
declare #OldJobCostRate decimal(19,4);
declare #BillingCategory smallint;
declare #Percent decimal(19,4);
if #PayRate is null or #PayRate = ''
set #PayRate = '0';
set #JobCostRate = CONVERT(decimal(19,4), #PayRate);
set #OldJobCostRate = #OldPayRate;
/* this works in T-SQL but when SSIS tries to validate I get a div/0 error */
if #OldJobCostRate != 0
begin
set #Percent = ((#JobCostRate - #OldJobCostRate)/#OldJobCostRate) * 100; --errors out right here with a divide by 0 error.
--set #Percent = 0;
end
else
begin
set #Percent = 0;
end
set #BillingCategory = CONVERT(smallint, #LaborCategory);
-- SQL statements for procedure here
-- Update EM table
-- Update EmployeeCustomTabFields table
-- Insert into Salary history table
END
GO
I have placed a comment on the line that produces the error. If I comment that line out and uncomment the one below it SSIS will validate the procedure without issue.
I finally worked around the issue by creating a derived field in the ETL but I would like to know why SSIS/OLE-DB is causing this issue for the next time it pops up.
Thanks,
Roy
If you alter your procedure to look like
SET NOCOUNT ON;
-- This is a bloody hack to get SSIS to be happy about metadata.
IF 1=2
BEGIN
SELECT 1 AS StupidHackery;
END
I believe you'll get around this issue. The root cause is that SSIS wants to validate the metadata from the proc and doesn't actually evaluate the logic in there. I don't have any definitive resources on the matter, pity, but for me at least, I could recreate your issue and by using this stupid hack, get around it. I've had to use the same thing when dealing with temporary tables.