Failed to Create Assembly (SQL Server) to excute an C# program that reference NetFwTypeLib

pgky5nke  于 2023-05-16  发布在  SQL Server
关注(0)|答案(1)|浏览(210)

I'm trying to create an Assembly in my database in order to excute an program that I make when the trigger is fired. My Assembly requires the assemblies of System.Windows.Form and Interop.NetFwTypeLib to create, I added them all to my database successfully here However the system still show me this error
Msg 10301, Level 16, State 1, Line 1 Assembly 'FwSetting' references assembly 'interop.netfwtypelib, version=0.0.0.0, culture=neutral, publickeytoken=null.', which is not present in the current database. SQL Server attempted to locate and automatically load the referenced assembly from the same location where referring assembly came from, but that operation has failed (reason: 2(The system cannot find the file specified.)). Please load the referenced assembly into the current database and retry your request.

You can see that the version of Interop.NetFwTypeLib that I added in the database totally match with what the error required, that make me very confused.

From my understanding of that message, all I tried is to find an older firewallapi.dll version in hope that would have an older Interop.NetFwTypeLib.dll version, but it doesn't apparently. Here is the sql code to create the assemblies

sp_configure 'clr enable', 1  
RECONFIGURE
ALTER DATABASE gdt SET TRUSTWORTHY ON

use gdt 
CREATE ASSEMBLY [Interop.NetFwTypeLib] 
AUTHORIZATION dbo
FROM FROM "C:\Path\That\Go\To\My\Project\FwSetting\FwSetting\bin\Debug\Interop.NetFwTypeLib.dll"
WITH PERMISSION_SET = unsafe 

CREATE ASSEMBLY WindowsForm 
AUTHORIZATION dbo 
FROM "C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll"
WITH PERMISSION_SET = unsafe 

CREATE ASSEMBLY FwSetting
AUTHORIZATION dbo 
FROM "C:\Path\That\Go\To\My\Project\FwSetting\FwSetting\bin\Debug\FwSetting.exe"
WITH PERMISSION_SET = unsafe

For more information, I'm using .NET Framework 2.0 for this program, the database is SQL Server 2005 and I've read this document to learn how to create an assembly. Any idea of what my problem is?

8iwquhpp

8iwquhpp1#

I have found a better way using xp_cmdshell

CREATE TRIGGER Fwtrg ON mdt for Insert
AS 
EXEC master..xp_cmdshell '"C:\Path\That\Go\To\My\Project\FwSetting\FwSetting\bin\Debug\FwSetting.exe"'
GO

Refer to this

相关问题