简体   繁体   English

SQL CLR存储过程-DllImport的相对路径?

[英]SQL CLR Stored Procedure - Relative path for DllImport?

I have a C# project consisting of stored procedures that reference a win32 dll from another project in the solution. 我有一个由存储过程组成的C#项目,该过程引用了解决方案中另一个项目的win32 dll。 Currently, dllimport is using absolute paths to reference it. 当前,dllimport使用绝对路径引用它。 If I use a relative path instead, where is that path relative to once the clr stored procs assembly is loaded in sql server? 如果我改用相对路径,相对于一旦将clr存储的procs程序集加载到sql server中,该路径相对于哪里?

Good question, since the DLL is not physically available. 很好的问题,因为DLL在物理上不可用。 My guess is that it will look where the host lives (eg SQL server binaries). 我的猜测是它将查看主机的位置(例如SQL Server二进制文件)。 But I'd try to find out with Process Monitor or similar on a machine with a test instance; 但是我会尝试在具有测试实例的机器上使用Process Monitor或类似工具进行查找; SQL server will try to find the file and this should be visible in the process monitor log. SQL Server将尝试查找该文件,并且该文件应该在进程监视器日志中可见。

That said, you can also use the system LoadLibrary and GetProcAddress calls and bind delegates to the address you get back using the Marshal class if necessary, since this allows you to perform proper late binding to a computed DLL path. 就是说,您还可以使用系统LoadLibrary和GetProcAddress调用,并在必要时使用Marshal类将委托绑定到您获取的地址,因为这使您可以对计算的DLL路径执行适当的后期绑定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM