Building .NET common language runtime (CLR) routine code using sample build scripts
Building .NET common language runtime (CLR) routine source code is a subtask of creating .NET CLR routines. You can use the sample batch files that are provided with the database to build .NET CLR routines more easily.
The sample build scripts can be used for source code with or without
SQL statements. The build scripts take care of the compilation, linking,
and deployment of the built assembly to the function directory
.
As alternatives, you can build .NET CLR routines in Visual Studio .NET to simplify the task or you can issue the commands in the sample build script manually.
- For C: sqllib/samples/cs/
- For C++: sqllib/samples/vb/
- Establishes a connection with a user-specified database
- Compiles and links the source code to generate an assembly with a .DLL file suffix
- Copies the assembly file to the database function directory on the database server
- The name of a source code file without any file suffix
- The name of a database to which a connection will be established
The database parameter is optional. If no database name is supplied, the program uses the default sample database. As routines must be built on the same instance where the database resides, no arguments are required for a user ID and password.
- Prerequisites
- The required .NET CLR routine operating system and development software prerequisites must be satisfied. See: "Support for .NET CLR routine development".
- Source code file containing one or more routine implementations.
- The name of the database within the current database instance in which the routines are to be created.
- Procedure
- To build a source code file that contains one or more routine code implementations, perform the following steps.
- Open the Db2 command window.
- Copy your source code file into the same directory as the bldrtn script file.
- If the routines will be created in the sample database, enter
the build script name followed by the name of the source code file
without the .cs or .vb file extension:
If the routines will be created in another database, enter the build script name, the source code file name without any file extension, and the database name:bldrtn file-name
The script compiles and links the source code and produces an assembly. The script then copies the assembly to the function directory on the database serverbldrtn file-name database-name
- If this is not the first time that the source code file containing the routine implementations was built, stop and restart the database to ensure the new version of the shared library is used by the database. You can do this by entering db2stop followed by db2start on the command line.
Once you have successfully built the routine shared library and deployed it to the function directory on the database server, you should complete the steps associated with the task of creating C and C++ routines.
Creating .NET CLR routines includes a step for executing the CREATE statement for each routine that was implemented in the source code file. After routine creation is completed you can invoke your routines.