Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > Scalar-Valued function View modes: 
User avatar
Member
Member
eagleag - 6/14/2010 12:01:43 PM
   
Scalar-Valued function
HI,
I need to use a Scalar-Valued function to populate a colum in one of my custom tables.
Is ther anyway to create one or something insted of it, throw the kentico interface?
I dont want to have issues when deploying site. might forget to transfer the SCALAR function or something :(

User avatar
Kentico Consulting
Kentico Consulting
kentico_mirekr - 6/15/2010 2:43:07 AM
   
RE:Scalar-Valued function
Hi,

I’m not quite sure if I understand you correctly, but you write your own query in Kentico CMS which will return some data from database according your needs and then you can execute this query from code. Example can be found in following documentation:

http://devnet.kentico.com/docs/devguide/data_layer_code_examples.htm

If you mean something else, please try to describe me your request in more detail using some examples.

Best regards,
Miroslav Remias

User avatar
Member
Member
eagleag - 6/16/2010 6:05:23 AM
   
RE:Scalar-Valued function
Hi,

I've added a Scalar-Valued function

FUNCTION [dbo].[upd_state_name]
(@satae_id int)
RETURNS VARCHAR(50)
AS
BEGIN
DECLARE @chkTable int
SET @chkTable = (select COUNT(ItemID) from customtable_CityTest1)
IF @chkTable>0
BEGIN
DECLARE @state_name VARCHAR(50)
SELECT @state_name = st.State
FROM Cagan_States st JOIN customtable_CityTest1 ctest
ON st.ItemID = ctest.[State]
WHERE ctest.[State] = st.ItemID

RETURN @state_name
END

RETURN NULL
END


function works when i try it in sql management studio.
In cms sitemanager -> development-> customTables -> tabelName -> Queries -> SelectAll
I put this code:

SELECT ItemID, ItemCreatedBy, upd_state_name(State), StateResult , City

FROM customtable_CityTest1


And i get this error when trying to view customTable in cmsdesk:

[DataConnection.ExecuteQuery]: Query: SELECT ItemID, ItemCreatedBy, upd_state_name(State), StateResult , City
FROM customtable_CityTest1: caused exception: 'upd_state_name' is not a recognized built-in function name.
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.Exception: [DataConnection.ExecuteQuery]: Query: SELECT ItemID, ItemCreatedBy, upd_state_name(State), StateResult , City
FROM customtable_CityTest1: caused exception: 'upd_state_name' is not a recognized built-in function name.


THANKS :)

User avatar
Kentico Consulting
Kentico Consulting
kentico_mirekr - 6/17/2010 7:46:35 AM
   
RE:Scalar-Valued function
Hi,

Could you please try to log on to your SQL server with SQL account which is used by your Kentico CMS and run the query from CSM Site Manager -> Development-> Custom Tables -> Table Name -> Queries -> SelectAll section? What is the result?

You can find the SQL account credentials in your web.config file in connectionstring section.

Are you sure that your custom SQL function is visible for the SQL account which is your Kentico CMS using?

Best regards,
Miroslav Remias.

User avatar
Member
Member
eagleag - 6/17/2010 9:10:05 AM
   
RE:Scalar-Valued function
HI,
I did what you said.
I logged into SQL server with SQL account which is used by your Kentico CMS.
I tried this query:

SELECT ItemID, ItemCreatedBy, upd_state_name(State), StateResult , City

FROM customtable_CityTest1


And got these errors:
Msg 195, Level 15, State 10, Line 1
'upd_state_name' is not a recognized built-in function name.

and when debugging got this msg:
Auto-attach to process '[4716] [SQL] (local)' on machine '(local)' succeeded.
The thread '(local)\sqlexpress [52]' (0x1b0) has exited with code 0 (0x0).
The thread '(local)\sqlexpress [52]' (0x1b0) has exited with code 0 (0x0).
The program '[4716] [SQL] (local): (local)\sqlexpress' has exited with code 0 (0x0).

any idea how i can solve this?

many thanks :)

User avatar
Member
Member
eagleag - 6/17/2010 9:25:38 AM
   
RE:Scalar-Valued function
I added dbo to functions name when calling it.

SELECT ItemID,  ItemCreatedBy, dbo.upd_state_name(State), StateResult , City

FROM customtable_CityTest1


now when i don't get any errors while running the query in kentico.

Thanks you very much for your help.

http://www.sql-server-helper.com/error-messages/msg-195.aspx