Creating Extended Stored Procedures

An extended stored procedure is a function with a prototype:

SRVRETCODE xp_extendedProcName (SRVPROC *);

Use of the prefix “xp_” is optional. Extended stored procedure names are case sensitive when referenced in TSQL statements regardless of code page/sort order installed on the server. An extended stored procedure is implemented in a 32-bit dynamic-linked library (DLL). When building a DLL:

These Open Data Services files are required for creating an extended stored procedure DLL.

File Description
Srv.h Open Data Services header file
Opends60.lib Import library for Opends60.dll

It is highly recommended that all Microsoft® SQL Server™ 7.0 extended stored procedure DLLs implement and export the following function:

__declspec(dllexport) ULONG __GetXpVersion()

{

    return ODS_VERSION;

}

  

When SQL Server loads an extended stored procedure DLL, it checks for the above function.


Note __declspec(dllexport) is a Microsoft-specific compiler extension. If your compiler does not support this directive, you should export this function in your .DEF file under the EXPORTS section.


When SQL Server is started with the trace flag -7260 or if a user with system administrator privileges runs DBCC TRACEON (260), then if the extended stored procedure DLL does not support __GetXpVersion(), a warning message (Error 8131: Extended stored procedure DLL ‘%” does not export __GetXpVersion().) is printed to the error log (Note that __GetXpVersion() begins with two underscores). If you get this message, and are running an extended stored procedure DLL compiled with headers and libraries from SQL Server version 6.x, refer to Backward Compatibility Details (Level 1). If you get this message and are running an extended stored procedure DLL compiled with headers and libraries from SQL Server 7.0, your extended stored procedure DLL is not exporting the function __GetXpVersion().

If the extended stored procedure DLL exports __GetXpVersion(), but the version returned by the function is less than that required by the server, a warning message (Error 8132: Extended stored procedure DLL ‘%’ reports its version is %d.%d. Server expects version %d.%d.) stating the version returned by the function and the version expected by the server is printed to the error log. If you get this message, you are returning an incorrect value from __GetXpVersion(), or you are compiling with an older version of srv.h

For more information about creating a DLL, see the development environment documentation and the Microsoft Win32® SDK documentation.

To create an extended stored procedure DLL by using Microsoft Visual C++

  1. Create a new project of type Win32 Dynamic Link Library.
  2. Set the directory for include files and library files to C:\Mssql7\DevTools\Include and C:\Mssql7\DevTools\Lib, respectively.
    1. On the Tools menu, click Options.
    2. In the Options dialog box, click the Directories tab and set the directory for include files and library files.
  3. On the Project menu, click Settings.
  4. In the Project Settings dialog box, click the Link tab. Click the General category, and then add opends60.lib to object/library modules.
  5. Add source files (.c, .cpp, and .rc files, and so on) to your project.
  6. Compile and link your project.

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.