MSSQL在库中找不到函数

MSSQL could not find the function in the library

本文关键字:找不到 函数 MSSQL      更新时间:2023-10-16

我想测试扩展存储过程(我知道它们现在不推荐使用,但出于个人原因,我想测试它们)。

我已经在VC++中生成了一个dll文件,这是我的代码:

//First.h
#include<iostream>
#include<srv.h>
using namespace std;
RETCODE _declspec(dllexport)  xp_firstfun(SRV_PROC *srvproc);

//main.cpp
#include<iostream>
#include "First.h"
using namespace std;

RETCODE xp_firstfun(SRV_PROC *srvproc)
{
    cout<<"Hello World froom DLL"<< endl;
    cin.get();
    return 0;
}

我可以用以下命令成功地将此dll添加到数据库:

sp_addextendedproc 'xp_firstfun', 'C:Program FilesMicrosoft SQL ServerMSSQL11.MSSQLSERVERMSSQLBinnFirstDLL.dll'

但是如果我尝试执行函数:

exec xp_firstfun

我面临这个错误:

在库C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Binn\FirstDLL中找不到函数xp_firstfun。原因:127(找不到过程)。

我有两个问题:

  • 我的C++代码正确吗
  • 我应该在SQL中做更多的事情来调用dll中的此函数吗

感谢您的帮助

更改您的声明。这可能会对您有所帮助,因为在c++中,函数名称在编译过程中会作为名称篡改的一部分进行修改。

extern "C"
{
    RETCODE _declspec(dllexport)  xp_firstfun(SRV_PROC *srvproc);
}