線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1942
推到 Plurk!
推到 Facebook!

請問如何用Delphi或BCB寫SQL Server的延伸預存程序

答題得分者是:Mickey
asupeduer
初階會員


發表:36
回覆:49
積分:27
註冊:2002-11-08

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-12-12 14:53:18 IP:61.13.xxx.xxx 未訂閱
請問各位高手, 因為我想在SQL Server某資料表After Insert後 自動執行一個延伸預存程序,「類似」發出一筆e_mail的這種功能, 當tirgger執行時,自動執行某個windows的工作, 例如很簡單的ShowMessage 如何寫這樣的延伸預存程序呢? //------------------------------------------------ 我常在想,寫程式跟爬格子到底有什麼不同呢??????????? //------------------------------------------------
------
//------------------------------------------------
我常在想,寫程式跟爬格子到底有什麼不同呢???????????
//------------------------------------------------
Mickey
版主


發表:77
回覆:1882
積分:1390
註冊:2002-12-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2002-12-12 15:30:57 IP:61.219.xxx.xxx 未訂閱
一言難盡,你可參考 MS SQL Server 線上說明. xp_startmail,xp_sendmail,xp_stopmail...
Mickey
版主


發表:77
回覆:1882
積分:1390
註冊:2002-12-11

發送簡訊給我
#3 引用回覆 回覆 發表時間:2002-12-13 13:15:40 IP:61.219.xxx.xxx 未訂閱
Dear asupeduer :    了解你的意圖後,敝人有興趣但不太認同 MSSQL 這個機制. DataBase serveice 之權限不應該,深及 OS ( Windows ), 因為如果 DataBase serveice 可以隨意去 create win process, 那意味著 DataBase Client 可藉由 DataBase serveice , 要 Database Server 幹任何事情 (包括關機,Format Hard Disk...), 只有 MicroSoft 純純深深相信人性本善, 難怪駭客族喜歡它.    話說歸說,在好奇心驅使下,還是做了一些嘗試,結果掙扎了一段 還是 po 上來.    -- Begin Delphi DLL Project library Project2;    uses   ShareMem,   SysUtils,   Classes;    {$R *.res}    function xp_test:boolean; stdcall; begin    result := False;    with TStringList.Create do begin    try       add('MSSQL Extend Store Procedure Test ('+datetimetostr(now)+')');       savetofile('c:\temp.txt');    finally       free;    end;    end;    result := True; end;    exports    xp_test; end. -- End Delphi DLL Project    -- MS SQL T-SQL -- ReCreate Extend Store Procedure use master go if exists       (select * from master.dbo.sysobjects where id = object_id('xp_test'))    execute  sp_dropextendedproc 'xp_test'  go    execute sp_addextendedproc 'xp_test', 'd:\temp\Project2.dll' go    -- Execute Extend Store Procedure begin    declare @c int    execute @c=xp_test    select @c end go -- procedure will run Project2.dll's "xp_test" and create & save "c:\temp.txt" file.< >< >< >< >
asupeduer
初階會員


發表:36
回覆:49
積分:27
註冊:2002-11-08

發送簡訊給我
#4 引用回覆 回覆 發表時間:2002-12-13 15:39:28 IP:61.13.xxx.xxx 未訂閱
先謝謝Mickey前輩,不過小弟是學BCB的, 現在手邊也沒有delphi,可以試,而對delphi語法又不是很熟, 所以還沒試過,但是MSSQL線上說明是需要引用下面兩個檔案說... Srv.h Open Data Services header file Opends60.lib Import library for Opends60.dll 不知Mickey前輩是否已經在MSSQL上測試過? 另外,其實您說的沒錯,資料庫可以動到WINDOWS OS的確不是很安全, 但是相對,也帶來更大彈性及空間呀,可以讓資料庫做些特異功能, 是不是代表似乎有更多,更寬廣的應用模式呢? 例如我們可以在不必考慮使用任何前端程式的情況下,每當新增一筆資料. 就開一個檔案或一個資料夾.在設計上是否更方便,更快速,且不會造成錯誤呢? 也可以說當更新一筆資料時,自動更新其他檔案等等的...... 然而權限及安全議題其實也不只是在這環節上有過,自古以來,也是善惡交戰, 這些就不用我們去擔心了,您說是麼...... 在此附上MSSQL的線上說明,其實是因為小弟功力差才不會用C 寫 也勞煩Mickey前輩了...... 另外有個不情之請,能否請Mickey前輩提示一下如何用bcb寫呢? 因為還是有點看不懂耶,抱歉抱歉...也在次謝謝Mickey前輩 Creating Extended Stored Procedures An extended stored procedure is a function with a prototype: SRVRETCODE xp_extendedProcName (SRVPROC *); Using the prefix "xp_" is optional. Extended stored procedure names are case sensitive when referenced in Transact-SQL statements, regardless of code page/sort order installed on the server. An extended stored procedure is implemented in a 32-bit dynamic-linked library (DLL). When you build a DLL: If an entry point is necessary, write a DllMain function. This function is optional; if you do not provide it in source code, the compiler links its own version, which does nothing but return TRUE. If you provide a DllMain function, the operating system calls this function when a thread or process attaches to or detaches from the DLL. All functions called from outside the DLL (all extended stored procedure functions) must be exported. You can export a function by listing its name in the EXPORTS section of a .def file, or you can prefix the function name in the source code with __declspec(dllexport), a Microsoft compiler extension (Note that __declspec() begins with two underscores). These Open Data Services files are required for creating an extended stored procedure DLL. File Description Srv.h Open Data Services header file Opends60.lib Import library for Opends60.dll It is highly recommended that all Microsoft® SQL Server™ 2000 extended stored procedure DLLs implement and export the following function: __declspec(dllexport) ULONG __GetXpVersion() { return ODS_VERSION; } When SQL Server loads an extended stored procedure DLL, SQL Server checks for the above function. Note __declspec(dllexport) is a Microsoft-specific compiler extension. If your compiler does not support this directive, you should export this function in your DEF file under the EXPORTS section. When SQL Server is started with the trace flag -T260 or if a user with system administrator privileges runs DBCC TRACEON (260), then if the extended stored procedure DLL does not support __GetXpVersion(), a warning message (Error 8131: Extended stored procedure DLL '%' does not export __GetXpVersion().) is printed to the error log (Note that __GetXpVersion() begins with two underscores). If you get this message, and you are running an extended stored procedure DLL compiled with headers and libraries from SQL Server version 6.x, refer to Level 1: Handling Discontinued Functionality. If you get this message and are running an extended stored procedure DLL compiled with headers and libraries from SQL Server 7.0, your extended stored procedure DLL is not exporting the function __GetXpVersion(). If the extended stored procedure DLL exports __GetXpVersion(), but the version returned by the function is less than that required by the server, a warning message (Error 8132: Extended stored procedure DLL '%' reports its version is %d.%d. Server expects version %d.%d.) stating the version returned by the function and the version expected by the server is printed to the error log. If you get this message, you are returning an incorrect value from __GetXpVersion(), or you are compiling with an older version of srv.h. Note SetErrorMode, a Microsoft Win32® function, should not be called in extended stored procedures. For more information about creating a DLL, see the development environment documentation and the Microsoft Win32 SDK documentation. To create an extended stored procedure DLL by using Microsoft Visual C Create a new project of type Win32 Dynamic Link Library. Set the directory for include files and library files to C:\Program Files\Microsoft SQL Server\80\Tools\DevTools\Include and C:\Program Files\Microsoft SQL Server\80\Tools\DevTools\Lib, respectively. On the Tools menu, click Options. In the Options dialog box, click the Directories tab and set the directory for include files and library files. On the Project menu, click Settings. In the Project Settings dialog box, click the Link tab. Click the General category, and then add opends60.lib to object/library modules. Add source files (.c, .cpp, and .rc files, and so on) to your project. Compile and link your project. //------------------------------------------------ 我常在想,寫程式跟爬格子到底有什麼不同呢??????????? //------------------------------------------------
------
//------------------------------------------------
我常在想,寫程式跟爬格子到底有什麼不同呢???????????
//------------------------------------------------
Mickey
版主


發表:77
回覆:1882
積分:1390
註冊:2002-12-11

發送簡訊給我
#5 引用回覆 回覆 發表時間:2002-12-13 15:56:39 IP:61.219.xxx.xxx 未訂閱
1. Delphi DLL Project 已有驗證過 with MSSQL 2000 OS Win2K Server. 2. MSSQL Online Help 那段不用理它, dll 就是 dll 哪來那末多限制. 3. 很抱歉 BCB 敝人不熟, 幫不上忙, 不過 Delphi ? BCB ? ... 那只不過是工具, dll 就是 dll, 不是嗎 ?
系統時間:2024-11-22 19:56:31
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!