下面以发送邮件为例,来简单说明如何使用SQL SERVER调用DLL的功能。
第一步:新建一个CS类库
using
System;
using
System.Collections.Generic;
using
System.Text;
using
System.Net.Mail;
using
System.Runtime.InteropServices;
namespace
BiSoftWare
...
{
[ComVisible(true)] <--此处为重点,表示此类能对COM类型公开。
public class BiSoftWare
...{
public bool SendMail(string from, string sendToCollection, string ccCollection, string bccCollection,
string replyTo,string subject, string body,string smtpSender, string smtpPassWord, string smtpHost)
...{
try
...{
string substr = null;
string temp = null;
MailMessage message = new MailMessage();
email initializtion#region email initializtion
message.From = new MailAddress(from);
message.IsBodyHtml = true;
message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
message.Priority = MailPriority.Normal;
#endregion

Assign the message values if they are valid.#region Assign the message values if they are valid.
if (!string.IsNullOrEmpty(sendToCollection))
...{
substr = sendToCollection.Trim();
while (substr.Contains(";")

本文介绍了如何在SQL Server中调用C#编写的DLL进行邮件发送。首先创建一个签名并编译为强命名的CS类库,然后将其复制到系统PATH路径下的system32目录。接着使用SDK命令提示工具注册DLL,最后在SQL Server中创建存储过程进行测试。注意在Master数据库中直接添加可能无法通过测试。
最低0.47元/天 解锁文章
966





