⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 在存储过程中调用外部的动态连接库.htm

📁 我在网上收集的一些有关vcDLL编程的文章。
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns:st1="urn:schemas-microsoft-com:office:smarttags"
xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=gb2312">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 11">
<meta name=Originator content="Microsoft Word 11">
<link rel=File-List href="在存储过程中调用外部的动态连接库.files/filelist.xml">
<link rel=Edit-Time-Data href="在存储过程中调用外部的动态连接库.files/editdata.mso">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<title>在存储过程中调用外部的动态连接库</title>
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
 name="chsdate" downloadurl=""/>
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
 name="chmetcnv" downloadurl=""/>
<!--[if gte mso 9]><xml>
 <o:DocumentProperties>
  <o:Author>pop</o:Author>
  <o:LastAuthor>pop</o:LastAuthor>
  <o:Revision>1</o:Revision>
  <o:TotalTime>0</o:TotalTime>
  <o:Created>2006-04-11T12:42:00Z</o:Created>
  <o:LastSaved>2006-04-11T12:42:00Z</o:LastSaved>
  <o:Pages>1</o:Pages>
  <o:Words>692</o:Words>
  <o:Characters>3951</o:Characters>
  <o:Company>baodi</o:Company>
  <o:Lines>32</o:Lines>
  <o:Paragraphs>9</o:Paragraphs>
  <o:CharactersWithSpaces>4634</o:CharactersWithSpaces>
  <o:Version>11.5606</o:Version>
 </o:DocumentProperties>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:SpellingState>Clean</w:SpellingState>
  <w:GrammarState>Clean</w:GrammarState>
  <w:PunctuationKerning/>
  <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
  <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
  <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
  <w:ValidateAgainstSchemas/>
  <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
  <w:IgnoreMixedContent>false</w:IgnoreMixedContent>
  <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
  <w:Compatibility>
   <w:SpaceForUL/>
   <w:BalanceSingleByteDoubleByteWidth/>
   <w:DoNotLeaveBackslashAlone/>
   <w:ULTrailSpace/>
   <w:DoNotExpandShiftReturn/>
   <w:AdjustLineHeightInTable/>
   <w:BreakWrappedTables/>
   <w:SnapToGridInCell/>
   <w:WrapTextWithPunct/>
   <w:UseAsianBreakRules/>
   <w:DontGrowAutofit/>
   <w:UseFELayout/>
  </w:Compatibility>
  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
 </w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:LatentStyles DefLockedState="false" LatentStyleCount="156">
 </w:LatentStyles>
</xml><![endif]--><!--[if !mso]><object
 classid="clsid:38481807-CA0E-42D2-BF39-B33AF135CC4D" id=ieooui></object>
<style>
st1\:*{behavior:url(#ieooui) }
</style>
<![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
	{font-family:宋体;
	panose-1:2 1 6 0 3 1 1 1 1 1;
	mso-font-alt:SimSun;
	mso-font-charset:134;
	mso-generic-font-family:auto;
	mso-font-pitch:variable;
	mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
	{font-family:"\@宋体";
	panose-1:2 1 6 0 3 1 1 1 1 1;
	mso-font-charset:134;
	mso-generic-font-family:auto;
	mso-font-pitch:variable;
	mso-font-signature:3 135135232 16 0 262145 0;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{mso-style-parent:"";
	margin:0cm;
	margin-bottom:.0001pt;
	text-align:justify;
	text-justify:inter-ideograph;
	mso-pagination:none;
	font-size:10.5pt;
	mso-bidi-font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:宋体;
	mso-font-kerning:1.0pt;}
span.SpellE
	{mso-style-name:"";
	mso-spl-e:yes;}
span.GramE
	{mso-style-name:"";
	mso-gram-e:yes;}
 /* Page Definitions */
 @page
	{mso-page-border-surround-header:no;
	mso-page-border-surround-footer:no;}
@page Section1
	{size:595.3pt 841.9pt;
	margin:72.0pt 90.0pt 72.0pt 90.0pt;
	mso-header-margin:42.55pt;
	mso-footer-margin:49.6pt;
	mso-paper-source:0;
	layout-grid:15.6pt;}
div.Section1
	{page:Section1;}
-->
</style>
<!--[if gte mso 10]>
<style>
 /* Style Definitions */
 table.MsoNormalTable
	{mso-style-name:普通表格;
	mso-tstyle-rowband-size:0;
	mso-tstyle-colband-size:0;
	mso-style-noshow:yes;
	mso-style-parent:"";
	mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
	mso-para-margin:0cm;
	mso-para-margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:10.0pt;
	font-family:"Times New Roman";
	mso-ansi-language:#0400;
	mso-fareast-language:#0400;
	mso-bidi-language:#0400;}
</style>
<![endif]-->
</head>

<body lang=ZH-CN style='tab-interval:21.0pt;text-justify-trim:punctuation'>

<div class=Section1 style='layout-grid:15.6pt'>

<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width="100%"
 style='width:100.0%;mso-cellspacing:0cm;mso-padding-alt:0cm 0cm 0cm 0cm'>
 <tr style='mso-yfti-irow:0;mso-yfti-firstrow:yes;height:30.0pt'>
  <td style='padding:0cm 0cm 0cm 0cm;height:30.0pt'>
  <p class=MsoNormal align=center style='text-align:center;mso-pagination:widow-orphan'><b><span
  style='font-size:12.0pt;font-family:宋体;mso-bidi-font-family:宋体;mso-font-kerning:
  0pt'>在存储过程中调用外部的动态连接库</span></b><span lang=EN-US style='font-size:9.0pt;
  font-family:宋体;mso-bidi-font-family:宋体;mso-font-kerning:0pt'><o:p></o:p></span></p>
  </td>
 </tr>
 <tr style='mso-yfti-irow:1;mso-yfti-lastrow:yes;height:18.75pt'>
  <td style='border:none;border-bottom:solid windowtext 1.5pt;padding:0cm 0cm 0cm 0cm;
  height:18.75pt'>
  <p class=MsoNormal align=center style='text-align:center;mso-pagination:widow-orphan'><span
  style='font-size:9.0pt;font-family:宋体;mso-bidi-font-family:宋体;mso-font-kerning:
  0pt'>【文章出处:转载】<span lang=EN-US>&nbsp;</span>【作者:未知】<span lang=EN-US>&nbsp;</span>【发布时间:<st1:chsdate
  Year="2005" Month="1" Day="25" IsLunarDate="False" IsROCDate="False" w:st="on"><span
   lang=EN-US>2005-01-25</span></st1:chsdate>】<span lang=EN-US>&nbsp;</span>【查看:
  <span lang=EN-US><script language="JavaScript"  src="/php/count.php?artID=10761&view=yes">
  </script>16</span>次】 <span lang=EN-US><o:p></o:p></span></span></p>
  </td>
 </tr>
</table>

<p class=MsoNormal align=left style='text-align:left;mso-pagination:widow-orphan'><span
lang=EN-US style='font-size:9.0pt;font-family:宋体;mso-bidi-font-family:宋体;
display:none;mso-hide:all;mso-font-kerning:0pt'><o:p>&nbsp;</o:p></span></p>

<div align=center>

<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width="96%"
 style='width:96.0%;mso-cellspacing:0cm;mso-padding-alt:0cm 0cm 0cm 0cm'>
 <tr style='mso-yfti-irow:0;mso-yfti-firstrow:yes;height:3.0pt'>
  <td colspan=3 style='padding:0cm 0cm 0cm 0cm;height:3.0pt'>
  <p class=MsoNormal align=left style='text-align:left;mso-pagination:widow-orphan'><span
  lang=EN-US style='font-size:3.0pt;mso-bidi-font-size:9.0pt;font-family:宋体;
  mso-bidi-font-family:宋体;mso-font-kerning:0pt'><o:p>&nbsp;</o:p></span></p>
  </td>
 </tr>
 <tr style='mso-yfti-irow:1;mso-yfti-lastrow:yes'>
  <td valign=top style='padding:0cm 0cm 0cm 0cm' id=fontzoom>
  <p class=MsoNormal align=left style='text-align:left;line-height:15.0pt;
  mso-pagination:widow-orphan'><span lang=EN-US style='font-size:10.0pt;
  font-family:宋体;mso-bidi-font-family:宋体;mso-font-kerning:0pt'><o:p>&nbsp;</o:p></span></p>
  <p class=MsoNormal align=left style='text-align:left;line-height:15.0pt;
  mso-pagination:widow-orphan'><span style='font-size:10.0pt;font-family:宋体;
  mso-bidi-font-family:宋体;mso-font-kerning:0pt'>问题的提出:<span lang=EN-US> <br>
  <br>
  </span>  一般我们要根据数据库的纪录变化时,进行某种操作。我们习惯的操作方式是在程序中不停的查询表,判断是否有新纪录。这样耗费的资源就很高,如何提高这种效率,我想在表中创建触发器,在触发器中调用外部动态连接<span
  class=GramE>库通过</span>消息或事件通知应用程序就可实现。而<span lang=EN-US>master</span>的存储过程中最好能调用外部的动态连接库,我们在触发器中调用<span
  lang=EN-US>master</span>的存储过程即可。<span lang=EN-US> <br>
  <br>
  </span>  说明<span lang=EN-US>:VC6</span>需要安装较新的<span lang=EN-US>Platform SDK</span>才能顺利编译本代码,<span
  lang=EN-US>VC.Net</span>可以直接编译本代码。另外还需要连接<span lang=EN-US>Opends60.lib</span>为了使没有较新<span
  lang=EN-US>Platform SDK</span>的朋友也能编译本例子,已经将<span lang=EN-US>VC.Net</span>中的<span
  class=SpellE><span lang=EN-US>Srv.h</span></span>和<span lang=EN-US>Opends60.lib</span>放到压缩包中<span
  lang=EN-US> <br>
  <br>
  </span>  程序实现:<span lang=EN-US> <br>
  <br>
  </span>  我们来实现一个存储过程中调用外部的<span class=SpellE><span lang=EN-US>dll</span></span>(<span
  lang=EN-US>storeproc.dll</span>)的函数<span class=SpellE><span lang=EN-US>SetFileName</span></span>和<span
  class=SpellE><span lang=EN-US>addLine</span></span>。<span lang=EN-US> <br>
  <br>
  </span>  存储过程如下(需放到<span lang=EN-US>master</span>库中):<span lang=EN-US> CREATE
  PROCEDURE <span class=SpellE>sp_testdll</span> AS <br>
  <br>
  exec <span class=SpellE>sp_addextendedproc</span> ''<span class=SpellE>SetFileName</span>'',
  ''storeproc.dll'' --</span>声明函数<span lang=EN-US> <br>
  exec <span class=SpellE>sp_addextendedproc</span> ''<span class=SpellE>addLine</span>'',
  ''storeproc.dll'' <br>
  <br>
  declare @<span class=SpellE>szFileName</span> <span class=SpellE>varchar</span></span>(<span
  lang=EN-US>200</span>)<span lang=EN-US> <br>
  declare @<span class=SpellE>szText</span> <span class=SpellE>varchar</span></span>(<span
  lang=EN-US>200</span>)<span lang=EN-US> <br>
  declare @<span class=SpellE>rt</span> <span class=SpellE>int</span> <br>
  <br>
  Select @<span class=SpellE>szFileName</span> = ''c:\welcome.txt'' <br>
  <br>
  EXEC @<span class=SpellE>rt</span> = <span class=SpellE>SetFileName</span> @<span
  class=SpellE>szFileName</span> --</span>调用<span class=SpellE><span
  lang=EN-US>SetFileName</span></span>函数,参数为<span lang=EN-US>--<span
  class=SpellE>szFileName</span>; <br>
  if @<span class=SpellE>rt</span> = 0 <br>
  begin <br>
  select @<span class=SpellE>szText</span> = ''welcome 01'' <br>
  Exec @<span class=SpellE>rt</span> = <span class=SpellE>addLine</span> @<span
  class=SpellE>szText</span> --</span>调用<span class=SpellE><span lang=EN-US>addLine</span></span><span
  lang=EN-US> <br>
  select @<span class=SpellE>szText</span> = ''welcome 02'' <br>
  Exec @<span class=SpellE>rt</span> = <span class=SpellE>addLine</span> @<span
  class=SpellE>szText</span> <br>
  <br>
  end <br>
  exec <span class=SpellE>sp_dropextendedproc</span> ''<span class=SpellE>SetFileName</span>''
  <br>
  exec <span class=SpellE>sp_dropextendedproc</span> ''<span class=SpellE>addLine</span>''
  <br>
  <br>
  <span class=SpellE>dbcc</span> <span class=SpellE>SetFileName</span></span>(<span
  lang=EN-US>free</span>)<span lang=EN-US> <br>
  <span class=SpellE>dbcc</span> <span class=SpellE>addLine</span></span>(<span
  lang=EN-US>free</span>)<span lang=EN-US> <br>
  <br>
  <br>
  </span>  动态连接库的实现:这种动态连接库和普通的有所不同。该动态连接库要放入<span lang=EN-US>SQL</span>的执行目录下,或直接放到<span
  lang=EN-US>Window</span>的<span lang=EN-US>System32</span>目录下<span lang=EN-US>,</span>并重起<span

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -