Call now: (800) 766-1884  


 SQL Server Tips
 SQL Server Training

 SQL Server Consulting
 SQL Server Support
 SQL Server Remote DBA

 SQL Server Scripts
 Scripts Menu




  SQL Server Tips by Gama and Naughter

Hello World in VB.NET

This sample is a function that will return a string. The function is implemented within a class and the class is part of a namespace (a namespace is a way of grouping a collection of classes). The code will be compiled into a .NET DLL (which is called an Assembly).

imports System
namespace HelloWorldNameSpace
public class HelloWorldClass
<SqlFunction()> public shared function HelloWorld() as string
return "Hello World!"
end function
public sub new()
end sub
end class
end namespace

The code can be saved anywhere as long as the DLL is created in the Binn folder under the folder where SQL Server 2005 is installed. Let us assume the default: C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Binn
After the DLL is created, it needs to be registered. This is done from the Script Editor with the following command:

CREATE ASSEMBLY HelloWorldNameSpace FROM 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Binn\HelloWorld.DLL'

The function from the assembly must be mapped to an internal UDF:

CREATE FUNCTION udfHelloWorld() returns nvarchar(4000)
as external name [HelloWorldNameSpace].[HelloWorldNameSpace.HelloWorldClass].HelloWorld

Now, the function can be used from SQL Server:

SELECT dbo.udfHelloWorld()

The result is:
Hello World!

To remove the function is very straightforward:


To remove the assembly:

DROP ASSEMBLY HelloWorldNameSpace

The above book excerpt is from:

Super SQL Server Systems
Turbocharge Database Performance with C++ External Procedures

ISBN: 0-9761573-2-2
Joseph Gama, P. J. Naughter


Burleson Consulting Remote DB Administration







Burleson is the America's Team

Note: The pages on this site were created as a support and training reference for use by our staff of DBA consultants.  If you find it confusing, please exit this page.

Errata?  SQL Server technology is changing and we strive to update our SQL Server support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:and include the URL for the page.

Burleson Consulting
SQL Server database support


Copyright 1996 -  2013 by Vaaltech Web Services. All rights reserved.

Hit Counter