再开一贴,继续向斑竹学习!

8992026 2002-06-26 09:54:05
如何在更改数据库的时候给特定的用户或进程发消息?欢迎讨论!

斑竹说自己做扩展存储过程来解决.但语焉不详,想来大部分人(包括本人)摸不着头脑,所以继续请教。

还有
我觉得问题是如何触发,斑竹能给我解释一下触发的机制吗,就是在更改数据库的时候能触发哪些事件,知道这个才知道在哪里写程序。
不知道是不是可以在扩展存储过程里就有办法解决?如何做呢?

真是摸不着头脑,还请说详细些!!
...全文
45 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
linyasa007 2002-06-28
  • 打赏
  • 举报
回复
学习
OpenVMS 2002-06-28
  • 打赏
  • 举报
回复
sample:
/*****************************************************************
NAME: xp_sendmymsg
*****************************************************************/
// This is an extended procedure DLL built with Open Data

// The Transact-SQL script xp_sendmymsg.sql installs and exercises the extended
// stored procedure.

#include <stdafx.h>
#include <stdlib.h>

#define XP_NOERROR 0
#define XP_ERROR 1

#define MAX_SERVER_ERROR 20000
#define xp_sendmymsg_ERROR MAX_SERVER_ERROR+1

ULONG __GetXpVersion()

{
return ODS_VERSION;
}

#ifdef __cplusplus
extern "C" {
#endif

void printUsage (SRV_PROC *pSrvProc);
void printError (SRV_PROC *pSrvProc, CHAR* szErrorMsg);

RETCODE __declspec(dllexport) xp_sendmymsg(SRV_PROC *pSrvProc);

#ifdef __cplusplus
}
#endif

// send XP main
RETCODE __declspec(dllexport) xp_sendmymsg(SRV_PROC *pSrvProc)
{
BYTE bType;
ULONG cbMaxLen;
ULONG cbActualLen;
BOOL fNull;

char* target;
int eventID;
char* str;

STS status;
static io_type io = channel;

// get the number of input parameters. There should be three.
if (srv_rpcparams(pSrvProc) != 3)
{
// Send error message and return
//
printUsage (pSrvProc);
return (XP_ERROR);
}


//Retrieve 1st input parameter (io handle name)
if (srv_paraminfo(pSrvProc, 1, &bType, &cbMaxLen, &cbActualLen,
NULL, &fNull) == FAIL)
{
printError (pSrvProc, "srv_paraminfo failed 1");
return (XP_ERROR);
}
// If there's data, then allocate memory and get it.
if (fNull == 0)
{
target = (char *) malloc(cbActualLen+1);
if (target == NULL)
{
printError (pSrvProc, "Memory allocation error 1");
return (XP_ERROR);
}

if (srv_paraminfo(pSrvProc, 1, &bType, &cbMaxLen,
&cbActualLen, (BYTE*) target, &fNull) == FAIL)
{
printError (pSrvProc, "Failed to retrieve parameter 1");
return (XP_ERROR);
}
}

target[cbActualLen] = 0; //put NULL on end of char


//Retrieve 2nd input parameter ( event number)
if (srv_paraminfo(pSrvProc, 2, &bType, &cbMaxLen,
&cbActualLen, (BYTE*) &eventID, &fNull) == FAIL)
{
printError (pSrvProc, "Failed to retrieve parameter 2");
// Free allocated memory
free (target);
return (XP_ERROR);
}


//Retrieve 3rd input parameter ( text)
if (srv_paraminfo(pSrvProc, 3, &bType, &cbMaxLen, &cbActualLen,
NULL, &fNull) == FAIL)
{
printError (pSrvProc, "srv_paraminfo failed 3");
return (XP_ERROR);
}
// If there's data, then allocate memory and get it.
if (fNull == 0)
{
str = (char *) malloc(cbActualLen+1);
if (str == NULL)
{
printError (pSrvProc, "Memory allocation error 3");
return (XP_ERROR);
}

if (srv_paraminfo(pSrvProc, 3, &bType, &cbMaxLen,
&cbActualLen, (BYTE*) str, &fNull) == FAIL)
{
printError (pSrvProc, "Failed to retrieve parameter 3");
free (target);
return (XP_ERROR);
}
}

str[cbActualLen] = 0; //put NULL on end of char


// Send a message to the receiver,replace it use your communication code
status = Send_Mymsg (io, 0, 0, channel, eventID, str, FALSE, FALSE);

// Free allocated memory
free (target);
free (str);

// Now return the number of rows processed
srv_senddone(pSrvProc, SRV_DONE_MORE | SRV_DONE_COUNT, (DBUSMALLINT)0, (DBINT)0);

return XP_NOERROR ;
}


// send XP usage info to client
void printUsage (SRV_PROC *pSrvProc)
{
srv_sendmsg(pSrvProc, SRV_MSG_ERROR, xp_sendmymsg_ERROR, SRV_INFO, 1,
NULL, 0, (DBUSMALLINT) __LINE__,
"Usage: EXECUTE xp_sendmymsg 'target', 'event name', 'str'",
SRV_NULLTERM);
srv_senddone(pSrvProc, (SRV_DONE_ERROR | SRV_DONE_MORE), 0, 0);
}

// send szErrorMsg to client
void printError (SRV_PROC *pSrvProc, CHAR* szErrorMsg)
{
srv_sendmsg(pSrvProc, SRV_MSG_ERROR, xp_sendmymsg_ERROR, SRV_INFO, 1,
NULL, 0, (DBUSMALLINT) __LINE__,
szErrorMsg,
SRV_NULLTERM);

srv_senddone(pSrvProc, (SRV_DONE_ERROR | SRV_DONE_MORE), 0, 0);
}
make11111 2002-06-28
  • 打赏
  • 举报
回复
对!学习ing……
baresi 2002-06-28
  • 打赏
  • 举报
回复
斑竹能否把捕获sql server事件的代码也贴出来
OpenVMS 2002-06-28
  • 打赏
  • 举报
回复
明天给出部分代码
xyqq 2002-06-27
  • 打赏
  • 举报
回复
接分
xhfjy 2002-06-27
  • 打赏
  • 举报
回复
@MARK@
liyunsong2000 2002-06-27
  • 打赏
  • 举报
回复
study
hzm_8 2002-06-27
  • 打赏
  • 举报
回复
学生越来越多,到了不少了,老师开讲吧!
leonnet 2002-06-27
  • 打赏
  • 举报
回复
来的不晚,坐好学习
duckcn 2002-06-27
  • 打赏
  • 举报
回复
学习ing
kaikaihe 2002-06-27
  • 打赏
  • 举报
回复
学习,学习,再学习。
CSDNM 2002-06-27
  • 打赏
  • 举报
回复
哦,还有这两个帖子!
斑竹给详细讲讲吧,我也想知道。
愉快的登山者 2002-06-27
  • 打赏
  • 举报
回复
学习,学习,再学习。
8992026 2002-06-27
  • 打赏
  • 举报
回复
哦,多了一个三角!
8992026 2002-06-27
  • 打赏
  • 举报
回复
主讲的快来呀!!!

这个帖子没有好的答案,我只好挂在这里了
baresi 2002-06-27
  • 打赏
  • 举报
回复
studing
CSDNM 2002-06-27
  • 打赏
  • 举报
回复
我也来听课
OpenVMS 2002-06-26
  • 打赏
  • 举报
回复
更正:源代码外方没有提供
OpenVMS 2002-06-26
  • 打赏
  • 举报
回复
就是用其他工具如VC写DLL,然后注册成SQL扩展存储过程。
我公司的系统就是这样做的,SP_SENDEVENT,但是源代码外方提供,我正在琢磨如何写与局域网上的应用进程进行通信的程序。
这是个很通用的问题,包括解决SQL里存储文件操作等问题,欢迎大家讨论。
加载更多回复(2)

34,588

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧