Monday, March 26, 2012
Esql/C calling stored procedure with output parameters
My stored procedure "aek_proc1" takes one input parameter (p1 - an 8-character string) and 3 output parameters (p2 - an integer; p3 - an 8-character string, and p4 a 40-character string).
My esqlc program contains the following code.
EXEC SQL BEGIN DECLARE SECTION;
char p1[9];
int p2;
char p3[9];
char p4[41];
WXEC SQL END DECLARE SECTION;
sprintf(&p1[0], "GL");
p2 = 0;
sprintf(&p3[0], "");
sprintf(&p4[0], "");
EXEC SQL EXECUTE aek_proc1 :p1,
:p2 OUTPUT,
:p3 OUTPUT,
:p4 OUTPUT;
I am getting errors at runtime about constants being passed for OUTPUT parameters.
I can run the same stored procedure in Query Analyser and it works beautifully (see below)
declare @.p1 char(8)
declare @.p2 integer
declare @.p3 char(8)
declare @.p4 char(40)
set @.p1 = 'GL'
execute aek_proc1 @.p1, @.p2 output, @.p3 output, @.p4 output
select @.p1 p1, @.p2 p2, @.p3 p3, @.p4 p4
Any idea what I'm doing wrong or how it should be coded?
I'd really appreciate any advice you can offer!!
I've spend hours browsing this newsgroup and found lots of examples of how to do this in VB and from Query Analyser but I can't find any examples for ESQL/C that work.
So, please help!!!
Thanks,
AllanK :rolleyes:Oops.
Don't know why the host variable names got turned into smileys, but that bit should have read...
EXEC SQL EXECUTE aek_proc1 :p1,
:p2 OUTPUT,
:p3 OUTPUT,
:p4 OUTPUT;|||Have you tried to replace : with @.?|||I tried changing the EXEC SQL EXEC command in the ESQL/C program to read...
EXEC SQL EXEC aek_proc1 @.p1, @.p2 OUTPUT, @.p3 OUTPUT, @.p4
after which I got the runtime error...
"0137- Must declare the variable '@.p1'."
I tried adding...
EXEC SQL DECLARE @.p1 char(8);
EXEC SQL DECLARE @.p2 int;
EXEC SQL DECLARE @.p3 char(8);
EXEC SQL DECLARE @.p4 char(40);
EXEC SQL SET @.p1 = 'GL';
EXEC SQL SET @.p2 = 0;
EXEC SQL SET @.p3 = '';
EXEC SQL SET @.p4 = '';
EXEC SQL EXEC aek_proc1 @.p1, @.p2 OUTPUT, @.p3 OUTPUT, @.p4 OUTPUT;
but the error persists.
Any further suggestions?
Thanks,
AllanK
Sunday, February 26, 2012
Error:Procedure or function CatalogJSummary has too many arguments specified
hello, all
I am using a Stored procedure and calling this in my code in C#.
Here is my procedure:
CatalogJSummary
(
@.SeriesId INT
)
AS
SELECT Games.GameName, Games.Id AS GameId
FROM GameCodes INNER JOIN
Games ON GameCodes.GameId = Games.Id INNER JOIN
MobileSeries ON GameCodes.SeriesId = MobileSeries.Id INNER JOIN
Mobiles ON MobileSeries.Id = Mobiles.SeriesId
GROUP BY Games.GameName, Games.Id, MobileSeries.Id
HAVING (MobileSeries.Id = @.SeriesId)
RETURN
and here is the calling C# code::
public DataSet CatalogJSummary(int sid)
{
SqlConnection cnUnique=new SqlConnection();
cnUnique.ConnectionString=System.Configuration.ConfigurationSettings.AppSettings["jconnection"];
//con.ConnectionString=System.Configuration.ConfigurationSettings.AppSettings["jconnection"];
com.CommandText="CatalogJSummary";
com.CommandType=CommandType.StoredProcedure;
com.Parameters.Add("@.SeriesId",SqlDbType.Int);
com.Parameters["@.SeriesId"].Value=sid;
com.Connection=cnUnique;
// con.Open();
cnUnique.Open();
adp=new SqlDataAdapter();
adp.SelectCommand=com;
DataSet ds1=new DataSet();
adp.Fill(ds1);
cnUnique.Close();
return ds1;
}
but when this code execute,with the parameter passed to stored procedure using this code at runtime, i get the following error::
Procedure or function CatalogJSummary has too many arguments specified.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Procedure or function CatalogJSummary has too many arguments specified.
Source Error:
Line 243:adp.SelectCommand=com; Line 244:DataSet ds1=new DataSet(); Line 245:adp.Fill(ds1); Line 246:cnUnique.Close(); Line 247:return ds1;
Source File: c:\inetpub\wwwroot\mobmasti.catalog\classes\truetonescls.cs Line: 245
Anyone please help me to resolve this error
thanks in advance
There are many options you can try:
1. From SQL Server books online:
If the first three characters of the procedure name are sp_, SQL Server
searches the master database for the procedure. If no qualified procedure name is provided, SQL Server searches for the procedure as if the owner name is dbo. To resolve the stored procedure name as a user-defined stored procedure with the same name as a system stored procedure, provide the fully qualified procedure name.
2. Make sure the field names between your calls and the procedure are the same
3. Make sure you attached the database with the user it was intended to be used with. Otherwise you may not have sufficient rights and this message will show up.