473,394 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to call a UDF from another UDF that is connected to an assembly

Seth Schrock
2,965 Expert 2GB
I'm probably making this harder than it has to be, but here is what I'm trying to do. I have created some functions in vb.net and then imported those functions as an assembly. I then created a UDF to be able to call those functions in the assembly. These functions require two arguments. The first I can pass to it as I call it. The second one is the value returned by a second UDF. What I'm currently doing is inside my query, I call the first function, give it the first argument (a field value) and then call the second UDF for the second argument. I would like to build the second UDF into the first so that when I call the first UDF, I only have to pass it the one argument and it would pull the second value on its own. This would just make it so that I have less typing when I need to call the function.
May 6 '14 #1

✓ answered by Rabbit

So when you call your function, can't you just do this:
Expand|Select|Wrap|Line Numbers
  1. [dbo].[EncryptString]('test string', dbo.PW())
Or if you don't want to pass the dbo.PW(), create a wrapper that will call it for you.
Expand|Select|Wrap|Line Numbers
  1. CREATE FUNCTION [dbo].[EncryptWrapper](@plainText [nvarchar](max)) 
  2. RETURNS [nvarchar](max)
  3. AS  
  4. RETURN [dbo].[EncryptString](@plainText, dbo.PW())
  5. GO 

8 1558
ck9663
2,878 Expert 2GB
Have you tried creating the function in SQL Server?


~~ CK
May 6 '14 #2
Seth Schrock
2,965 Expert 2GB
The .net function is not something that can be done in SQL Server as far as I know, if that is what you are talking about. The other two functions are in SQL Server.
May 6 '14 #3
Rabbit
12,516 Expert Mod 8TB
There shouldn't be a problem calling a function from within a function. Can you post the function code?
May 6 '14 #4
ck9663
2,878 Expert 2GB
If not the code of the assembly, try giving us what your function is trying to do. We might be able to reconstruct it in sql server.


~~ CK
May 7 '14 #5
Seth Schrock
2,965 Expert 2GB
So if I have a nested function, then I will have what I call the parent function (the one called in the queries) and the child function (the one that is called by the parent function). The code for the parent function is
Expand|Select|Wrap|Line Numbers
  1. CREATE FUNCTION [dbo].[EncryptString](@plainText [nvarchar](max), @PW [nvarchar](max))
  2. RETURNS [nvarchar](max) WITH EXECUTE AS CALLER
  3. AS 
  4. EXTERNAL NAME [VB_Encryption_Test].[VB_Encryption_Test.AESManagedProc].[Encrypt]
  5. GO
The code for the child function is
Expand|Select|Wrap|Line Numbers
  1. CREATE FUNCTION [dbo].[PW]()
  2. RETURNS nvarchar(max)
  3. AS
  4. BEGIN
  5.     DECLARE @PWD nvarchar(max)
  6.     DECLARE @ID smallint
  7.     SET @ID = 2   --Change for individual database
  8.     SELECT @PWD = PW
  9.     FROM tempdb.dbo.PasswordTable
  10.     WHERE PWID = @ID;
  11.     RETURN @PWD
  12. END;
So instead of the EncryptString function requiring the PW argument, I just want the function to automatically call the PW function.

@CK The code that the assembly links to encrypts and decrypts the data. I know that SQL Server has the ability to encrypt and decrypt data, but my problem is that I am linking to the data from MS Access and I can't open a key from Access nor can a function change the state of the database. So to make the data easily modified through Access, I import a view instead of the actual table. The view decrypts the data automatically. Then I have Insert and Update triggers to encrypt the data that I change and then pass the encrypted data on to the table. If you have another solution I would love to hear it, but I have searched for months trying to figure out a way to encrypt/decrypt data in SQL Server in a manner that allows for easy integration with Access.
May 7 '14 #6
Rabbit
12,516 Expert Mod 8TB
So when you call your function, can't you just do this:
Expand|Select|Wrap|Line Numbers
  1. [dbo].[EncryptString]('test string', dbo.PW())
Or if you don't want to pass the dbo.PW(), create a wrapper that will call it for you.
Expand|Select|Wrap|Line Numbers
  1. CREATE FUNCTION [dbo].[EncryptWrapper](@plainText [nvarchar](max)) 
  2. RETURNS [nvarchar](max)
  3. AS  
  4. RETURN [dbo].[EncryptString](@plainText, dbo.PW())
  5. GO 
May 7 '14 #7
Seth Schrock
2,965 Expert 2GB
The top line is what I currently do. But since I have to type it for each field that I want encrypted, I was looking to reduce the amount of typing I would have to do. The wrapper looks like just thing that I'm looking for. I'll give that a try and let you know if I have any issues.
May 7 '14 #8
Seth Schrock
2,965 Expert 2GB
That worked. Thanks Rabbit.
May 8 '14 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
1
by: Daniel | last post by:
how to load a C# dll from another C# assembly if the path of the loaded dll is not known until runtime
3
by: Le, Thanh-Nhan | last post by:
Hi, How can I from constructor of a class call another constructor? As following (as in Java): public class Test { public Test() {
1
by: Galaxia | last post by:
Hi, I am using C# of VS .Net 2003. I want to call another executable file (.exe) in my program. How can I do it? Thanks. -- "Forward Galaxia"
1
by: Ed | last post by:
I would like to call another on_click procedure but fail... e.g. Sub try() call button2_click() ' what should i put in (??, ??) since I don't know the source and asg... in order to call button...
2
by: Progman | last post by:
Id like to call another aspx page from a script area from a procedure. the only way i found is: Me.Controls.Clear() Server.Execute("AnotherPage.aspx) Is there a better way?
18
by: cmk128 | last post by:
hi 1 #include <stdio.h> 2 3 class A{ 4 private: 5 int x; 6 public: 7 A(int x){ 8 this->x;
3
by: fish919 | last post by:
Hello All, I am creating a date base in access. I want to create a dropdown list box that is connected to another dropdown list box. You start with a dropdown list that has 5 choices and each of...
5
by: Warren Tang | last post by:
Hello, Does C++ allow a constructor to call another constructor of the same class? (I am focusing on the language abilities. I know the C# language allow this.) The following sample can...
6
by: Christopher | last post by:
Its been awhile and I am rusty. Can the constructor of my class call another method in the same class if that other method does not change any member data? I want to simply have a seperate...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.