StrataFrame Forum
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      


12»»

Using DataBasics to execute a non-bo-bound...Expand / Collapse
Author
Message
Posted 08/26/2008 4:53:02 AM


StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: StrataFrame Users
Last Login: Today @ 5:21:05 AM
Posts: 68, Visits: 163
Hi,

I am wondering if someone could provide a sample code as how I can use

DataBasics.DataSources[""].ExecuteStoredProcedure(..)

 

My sproc takes 2 varchar input parameters and returns an integer value:

@HWID VARCHAR(250),

@ComputerName VARCHAR(250),

@iKassenId int OUTPUT

 

i want to execute the sproc and get the Result integer.

Thanks !

 

Post #18725
Posted 08/26/2008 5:59:04 AM


StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: StrataFrame Users
Last Login: Today @ 5:21:05 AM
Posts: 68, Visits: 163
i tried it like that and get a NULLREFERENCE exception:

int iResult = 0;

System.Data.Common.DbParameter[] spParams = new System.Data.SqlClient.SqlParameter[2];

spParams[0].Value = "123123123";

spParams[1].Value = "Computer1";

iResult = (int)DataBasics.DataSources[""].ExecuteStoredProcedure("spK_KassenAnmeldung", DbCommandExecutionType.ExecuteScalar, spParams);

Post #18728
Posted 08/26/2008 6:38:25 AM


StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: StrataFrame Users
Last Login: Today @ 5:21:05 AM
Posts: 68, Visits: 163
heres the complete code:

private static int KassenAnmeldung()

{

System.Data.Common.DbParameter[] spParams = new System.Data.SqlClient.SqlParameter[2];

spParams[0] = new System.Data.SqlClient.SqlParameter();

spParams[1] = new System.Data.SqlClient.SqlParameter();

spParams[0].ParameterName = "@HWID";

spParams[1].ParameterName = "@ComputerName";

spParams[0].Value = "123123123";

spParams[1].Value = "Computer1";

return (int)DataBasics.DataSources[""].ExecuteStoredProcedure("spK_KassenAnmeldung", DbCommandExecutionType.ExecuteScalar, spParams);

}

the stored procedure itself works. i tested it within sql management studio:

DECLARE @i int

EXEC @i= spK_KassenAnmeldung '123123123','Computer9';

select @i

Post #18729
Posted 08/26/2008 8:51:00 AM


StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: StrataFrame Users
Last Login: Today @ 5:21:05 AM
Posts: 68, Visits: 163
Shorter Code, but same error:

private static int KassenAnmeldung()

{

return (int)DataBasics.DataSources[""].ExecuteStoredProcedure("spK_KassenAnmeldung", DbCommandExecutionType.ExecuteScalar, new System.Data.SqlClient.SqlParameter("@HWID", "123123123"),new System.Data.SqlClient.SqlParameter("@ComputerName", "Computer9"));

}

For some reason the Object returned by executestoredprocedure has a value of NULL.

Executing the same sproc on the sql management studio with the same parameters returns a nice integer value.

i dont get it ?

Post #18732
Posted 08/26/2008 9:09:44 AM
StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: StrataFrame Users
Last Login: Today @ 1:01:15 PM
Posts: 67, Visits: 1,169
Hi Phillip,

Does your procedure run fine (and returns a nice integer value) when executed from within a BO?

And why not using a BO?
I've a lot of SP and Scalar functions on a SQL database, all in dbo schema, and I use any of my BOs (no one connecting on dbo schema) to run theses SP and functions (you need to grant exec in an intermediate SP, or execute as ..., and revert after execution)

Post #18733
Posted 08/26/2008 9:20:53 AM


StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: StrataFrame Users
Last Login: Today @ 5:21:05 AM
Posts: 68, Visits: 163
HI Michel,

thanks for you reply. i dont know i it runs using a bo, and for this particular function i dont really want to use a bo.

i dont quite understand what you mean by:

(you need to grant exec in an intermediate SP, or execute as ..., and revert after execution)

From the Help-Document, the ExecuteStoredProcedure function is capable of doing what i want. i dont understand why i would need to use a bo for it. ?

Post #18734
Posted 08/26/2008 9:24:01 AM
StrataFrame Team Member

StrataFrame Team Member

Group: StrataFrame Users
Last Login: 12/23/2008 11:10:40 AM
Posts: 232, Visits: 511
Your code looks good. What is in your stored procedure?

I just made a test that comes accross fine using the StrataFrame sample. Here is my SF code:

Dim spParams As System.Data.Common.DbParameter() = {New System.Data.SqlClient.SqlParameter}
spParams(0).ParameterName = "@cust_pk"
spParams(0).Value = "1"
Dim test As String = MicroFour.StrataFrame.Data.DataBasics.DataSources("").ExecuteStoredProcedure("GetCustomerLastName", MicroFour.StrataFrame.Data.DbCommandExecutionType.ExecuteScalar, spParams)

And here is the alter for my stored procedure:

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[GetCustomerLastName]
-- Add the parameters for the stored procedure here
@cust_pk int = 1
AS
BEGIN
-- Insert statements for procedure here
SELECT cust_LastName FROM Customers WHERE cust_pk = @cust_pk
END

 

Post #18735
Posted 08/26/2008 9:24:59 AM


StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: StrataFrame Users
Last Login: Today @ 5:21:05 AM
Posts: 68, Visits: 163
Hi Dustin,

this is my sproc:

set ANSI_NULLS ON

set QUOTED_IDENTIFIER ON

GO

ALTER PROCEDURE [dbo].[spK_KassenAnmeldung]

@HWID VARCHAR(250),

@ComputerName VARCHAR(250)

AS

DECLARE @iKassenId int

SET @iKassenId = ( SELECT TOP 1 ID FROM tbKassen WHERE

HWID = @HWID AND ComputerName = @ComputerName );

IF ( @iKassenId IS NULL )

BEGIN

DECLARE @iKassenNr int;

SET @iKassenNr = ( SELECT count(*) FROM tbKassen );

INSERT INTO tbKassen (Bezeichnung, Zyklus, HWID, ComputerName)

VALUES ('Kasse'+LTRIM(STR(@iKassenNr)) , 0, @HWID, @ComputerName);

SET @iKassenId = SCOPE_IDENTITY();

END

RETURN @iKassenId

Post #18736