在預存程序中調用外部的動態串連庫

來源:互聯網
上載者:User

問題的提出:

一般我們要根據資料庫的紀錄變化時,進行某種操作。我們習慣的操作方式是在程式中不停的查詢表,判斷是否有新紀錄。這樣耗費的資源就很高,如何提高這種效率,我想在表中建立觸發器,在觸發器中調用外部動態串連庫通過訊息或事件通知應用程式就可實現。而master的預存程序中最好能調用外部的動態串連庫,我們在觸發器中調用master的預存程序即可。

說明:VC6需要安裝較新的Platform SDK才能順利編譯本代碼,VC.Net可以直接編譯本代碼。另外還需要串連Opends60.lib

為了使沒有較新Platform SDK的朋友也能編譯本例子,已經將VC.Net中的Srv.h和Opends60.lib放到壓縮包中

程式實現:

我們來實現一個預存程序中調用外部的dll(storeproc.dll)的函數SetFileName和addLine。

預存程序如下(需放到master庫中):

CREATE PROCEDURE sp_testdll AS
exec sp_addextendedproc 'SetFileName', 'storeproc.dll'  --聲明函數
exec sp_addextendedproc 'addLine', 'storeproc.dll'
declare @szFileName varchar(200)
declare @szText varchar(200)
declare @rt int
Select @szFileName = 'c:\welcome.txt'
EXEC @rt = SetFileName @szFileName  --調用SetFileName函數,參數為--szFileName;
if @rt = 0
begin
select @szText = 'welcome 01'
Exec @rt = addLine @szText          --調用addLine
select @szText = 'welcome 02'
Exec @rt = addLine @szText
end
exec sp_dropextendedproc 'SetFileName'
exec sp_dropextendedproc 'addLine'
dbcc SetFileName(free)
dbcc addLine(free)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.