Building .NET common language runtime (CLR) routine code from the Db2 command window
You can build .NET CLR routine from the command line.
Before you begin
As an alternative to manually building the .NET CLR routines, you can use the sample build scripts that are provided in the sample subdirectory of the sqllib directory or build the routine in the Visual Studio .NET project.
The following conditions must be met before you can build the .NET CLR routines.- Prerequisite requirements for the operating system and the .NET CLR routine development software must be met.
- You must have a .NET CLR routine source code that is written in a supported .NET CLR programming language.
- You must have the database information in which the routines are to be created.
- You must have compiler options that are operating system specific and link options that are required for building .NET CLR routines.
Procedure
To build a source code file that contains one or more .NET CLR routine code implementations:
- Open the Db2 command window.
- Navigate to the directory that contains your source code file.
- Establish a connection with the database in which the routines are created.
- Compile the source code file.
- Link the source code file to generate a shared library. The linking process requires the use of compiler link options that references the database include directory.
- Copy the assembly file with the .DLL file suffix to the database function directory on the database server.
- If you are not building the source code file for the first time, you must stop and restart the database manager to ensure that the new version of the shared library is used by the database manager. You can issue the db2stop command followed by the db2start command to restart the database manager.
Results
Example
myVBfile.vb
Visual
Basic code file and the myCSfile.cs
C# code file
that contains routine implementations. The routines are being built
with the Microsoft .NET
Framework on a Windows operating
system to generate a 64-bit assembly. Open the Db2 command window.
Navigate to the directory that contains your source code file.
- Establish a connection with the database to which the routine is intended for.
Db2 connect to database-name
- Compile the source code file and specify any compiler options
that you need to specify. You must reference the IBM® .NET data provider file location. In the
following example. the
$DB2PATH
environment variable represents the IBM data server product installation path:C# example =================== csc /out:myCSfile.dll /target:library /reference:$DB2PATH%\bin\netf40\IBM.Data.DB2.dll myCSfile.cs Visual Basic example ==================== vbc /target:library /libpath:$DB2PATH\bin\netf40 /reference:$DB2PATH\bin\netf40\IBM.Data.DB2.dll /reference:System.dll /reference:System.Data.dll myVBfile.vb
The compiler displays an output to indicate whether there are any errors.
- Copy the shared library to the database function directory
on the database server.
C# example ==================== rm -f ~HOME/sqllib/function/myCSfile.DLL cp myCSfile $HOME/sqllib/function/myCSfile.DLL Visual Basic example ==================== rm -f ~HOME/sqllib/function/myVBfile.DLL cp myVBfile $HOME/sqllib/function/myVBfile.DLL
This step ensures that the routine library is in the default directory where the database manager looks for routine libraries.
- Stop and restart the database manager.
db2stop db2start
You can modify the sample build scripts that are provided in the sample subdirectory of the sqllib directory to simplify building the .NET CLR routines.