다음을 통해 공유


Creating Extended Stored Procedures

ms164627.note(ko-kr,SQL.90).gif중요:
Microsoft SQL Server의 이후 버전에서는 이 기능이 제거됩니다. 새 개발 작업에서는 이 기능을 사용하지 말고, 현재 이 기능을 사용하는 응용 프로그램은 가능한 한 빨리 수정하십시오. Use CLR Integration instead.

An extended stored procedure is a function with a prototype:

SRVRETCODE xp_extendedProcName **(**SRVPROC *);

Using the prefix xp_ is optional. Extended stored procedure names are case sensitive when referenced in Transact-SQL statements, regardless of code page/sort order installed on the server. When you build a DLL:

  • If an entry point is necessary, write a DllMain function.
    This function is optional; if you do not provide it in source code, the compiler links its own version, which does nothing but return TRUE. If you provide a DllMain function, the operating system calls this function when a thread or process attaches to or detaches from the DLL.
  • All functions called from outside the DLL (all extended stored procedure Efunctions) must be exported.
    You can export a function by listing its name in the EXPORTS section of a .def file, or you can prefix the function name in the source code with __declspec(dllexport), a Microsoft compiler extension (Note that __declspec() begins with two underscores).

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

File Description

Srv.h

Extended Stored Procedure API header file

Opends60.lib

Import library for Opends60.dll

To create an extended stored procedure DLL, create a project of type Dynamic Link Library. For more information about creating a DLL, see the development environment documentation.

It is highly recommended that all extended stored procedure DLLs implement and export the following function:

__declspec(dllexport) ULONG __GetXpVersion()
{
   return ODS_VERSION;
}

[!참고] __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 -T260 or if a user with system administrator privileges runs DBCC TRACEON (260), and 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 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 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.

[!참고] SetErrorMode, a Microsoft Win32 function, should not be called in extended stored procedures.

It is recommended that a long-running extended stored procedure should call srv_got_attention periodically so that the procedure can terminate itself if the connection is killed or the batch is aborted.

To debug an extended stored procedure DLL, copy it to the SQL Server\Binn directory. To specify the executable for the debugging session, enter the path and file name of the Microsoft SQL Server executable file (for example, C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Binn\Sqlservr.exe). For information about sqlservr arguments, see sqlservr 응용 프로그램.

참고 항목

참조

srv_got_attention (Extended Stored Procedure API)

도움말 및 정보

SQL Server 2005 지원 받기