我們接着要調用的DLL從DLL
SQL Server 2005(在觸發器中)並傳遞DLL一些變量並獲得返回值。
im在這個過程中。
我所創建的DLL 'HTTPDLL.dll'
來源:
Imports System
Imports System.Configuration
Imports System.Collections.Generic
Imports System.Text
Imports System.Net
Imports System.Security
Imports System.Security.Permissions
Imports System.IO
Imports Microsoft.SqlServer.Server
Public Class HTTPDLL
Public Function HTTPPost(ByVal URL As String, ByVal Content As String) As Boolean
Dim myURL As String = Trim(URL)
Dim mycontent As String = Trim(Content)
Dim rawOutput As String = ""
'Get Acces Right to web
Dim p As New WebPermission(NetworkAccess.Connect, myURL)
p.Assert()
'Prepare the web Request
Dim req As WebRequest = WebRequest.Create(myURL)
req.Timeout = 60000
req.Method = "POST"
req.ContentLength = mycontent.Length
req.ContentType = "application/x-www-form-urlencoded"
Dim sw As New StreamWriter(req.GetRequestStream())
sw.Write(mycontent)
sw.Close()
Dim resp As WebResponse = req.GetResponse()
Dim sr As New StreamReader(resp.GetResponseStream)
rawOutput = sr.ReadToEnd()
sr.Close()
Return True
End Function
Public Function Test() As Integer
Return 1
End Function
Public Function DllMain(ByVal hInst As Long, ByVal fdwReason As Long, _
ByVal lpvReserved As Long) As Boolean
Dim s As String = "sdfghjkolihdgjkhgiueghkyhekygigdjhgfkhsgdkhfgksjdhgkjshdgfkjhsgdkjfhgkshdgfkjhgskjdhgfkjhsdgkfhgskjdhfgkjsdhgfkshdgfkhgsdkfhgksdhfgkshdgfkshdgfkjhsgdkfhgskdhfgksjdhgfkjshgdfkhsgdkfhgskdhfgkshgdfkjhgskdjg"
s &= "kjhdgjkshkdjfhklsjdhfljhgkhvbfiuvbli klrfgliu ghliebliuhdflivbdkljhgljuhfvliuhdf"
Return True
End Function
End Class
我已經放置在SQL服務器C的DLL:/在Windows/System文件夾
我已經裝這些程序集
HelloWorld System.Core System.XML.Linq
使用這些命令
EXEC sp_configure 'show advanced options' , '1';
go
reconfigure
go
EXEC sp_configure 'clr enabled' , '1'
go
sp_configure 'Ole Automation Procedures', '1'
GO
RECONFIGURE
-- Turn advanced options back off
EXEC sp_configure 'show advanced options' , '0';
go
reconfigure
GO
-- assembly style
ALTER DATABASE master SET TRUSTWORTHY ON
GO
CREATE ASSEMBLY [System.Core]
AUTHORIZATION [dbo]
FROM 'C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll'
WITH PERMISSION_SET = UNSAFE
GO
CREATE ASSEMBLY [System.Xml.Linq]
AUTHORIZATION [dbo]
FROM 'C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll'
WITH PERMISSION_SET = UNSAFE
GO
create assembly HelloWorld from 'C:\WINDOWS\system\HTTPDLL.dll'
with permission_set = safe
GO
我加入的擴展過程
USE [master]
GO
/****** Object: ExtendedStoredProcedure [dbo].[HTTPDLL] Script Date: 02/03/2010 11:45:28 ******/
EXEC dbo.sp_addextendedproc N'HTTPDLL', 'C:\WINDOWS\system\HTTPDLL.dll'
(在這一點上的IM不知道爲什麼,或者如果我需要添加的組件,因爲這直接引用的DLL。 )
我需要解決的問題。 我現在想要調用DLL的(擴展程序)HTTPPost功能
我曾嘗試 EXEC HTTPPost 「消息17750,級別16,狀態0,過程HTTPPost,1號線 無法加載DLL的HelloWorld,或其中一個它引用的DLL。原因:126(找不到指定的模塊)。「
exec HelloWorld.HTTPPost 'http://www.somewebsite.com',''
「消息2812,級別16,狀態62,第1行 未能找到存儲過程 'HelloWorld.HTTPPost'。」
我需要的是: 如果你可以看看我的實踐,看看我是否正確設置了一切,並告訴我(用例子請)如何正確調用該DLL,發送變量並獲取其返回值。我會非常感激。
我已經瀏覽了很多帖子/文章,並且已經得到了很多東西,這些東西已經吸引我到目前爲止,但沒有一個包容性。
我也試過這種
-- Scratch variables used in the script
DECLARE @retVal INT
DECLARE @comHandle INT
DECLARE @errorSource VARCHAR(8000)
DECLARE @errorDescription VARCHAR(8000)
DECLARE @retString VARCHAR(100)
-- Initialize the COM component.
EXEC @retVal = sp_OACreate 'HTTPDLL.HTTPDLL', @comHandle OUTPUT
IF (@retVal <> 0)
BEGIN
-- Trap errors if any
EXEC sp_OAGetErrorInfo @comHandle, @errorSource OUTPUT, @errorDescription OUTPUT
SELECT [Error Source] = @errorSource, [Description] = @errorDescription
RETURN
END
(以及其他類似的變種) 和sp_OAGetErrorInfo會
「錯誤源說明 ODSOLE擴展過程無效的類字符串」
的回報得到這個也許我錯誤地稱它,但我還沒有能夠得到它的工作(總是返回'無效類字符串')
預先感謝您的幫助!