简体   繁体   English

读取Service Broker队列(SQL Server 2005)时获取主机名

[英]Get hostname when reading Service Broker Queue (SQL Server 2005)

I am trying to configure auditing on my SQL Server using Service Broker. 我正在尝试使用Service Broker在SQL Server上配置审核。 I did all the configuration needed to capture the DDL Events (queue, routes, endpoints, event notification). 我完成了捕获DDL事件(队列,路由,端点,事件通知)所需的所有配置。 It is working properly except that I am not able to get the hostname of the client from where the DDL event originated from. 它工作正常,但无法从DDL事件起源的地方获取客户端的主机名。

Using the service broker's activation procedure, I tried reading the value from the message_body, but there's no xml element that contains the hostname. 使用服务代理的激活过程,我尝试从message_body中读取值,但是没有包含主机名的xml元素。 I can see a value for the SPID but am unable to make use of it. 我可以看到SPID的值,但无法使用它。 Exec'ing sp_who and querying sys.processes against this SPID doesn't return any value. 对这个SPID执行sp_who并查询sys.processes不会返回任何值。 And running sp_who without parameter shows only one process (I think it's the background process used by the service broker). 运行不带参数的sp_who仅显示一个进程(我认为这是服务代理使用的后台进程)。 Is it all because the message was sent asynchronously? 是否全部是因为消息是异步发送的? But why will it cause the activation context to see different data on sys.processes view? 但是,为什么它会导致激活上下文在sys.processes视图上看到不同的数据?

I am aware that there are DDL triggers that can achieve the same goal, but it seems it is tightly coupled to the command that causes it to fire. 我知道有些DDL触发器可以实现相同的目标,但是似乎它与导致它触发的命令紧密相关。 So if the triggers fails, the command will also fail. 因此,如果触发器失败,该命令也会失败。

UPDATE: I managed to retrieve the Hostname by using a combination of xp_cmdshell and sqlcmd (command line app). 更新:我设法通过使用xp_cmdshell和sqlcmd(命令行应用程序)的组合来检索主机名。 But I also realized that since the message is asynchronous, it is not always reliable (The SPID who issue the DDL command might have been disconnected already before the message is read from the queue). 但是我也意识到,由于消息是异步的,因此并不总是可靠的(发出DDL命令的SPID可能已经从队列中读取消息之前就已经断开了连接)。

I'm not exactly sure what you're trying to implement here, but it's expected that activated procedure will only see a subset of rows in DMVs. 我不确定您要在此处实现什么,但是可以预期已激活的过程将仅看到DMV中的行的子集。 This has to do with activation context which often impersonates a different user that you use when debugging the procedure. 这与激活上下文有关,激活上下文通常模拟您在调试过程时使用的其他用户。 That impersonated user will only see these rows of server-level views and DMVs to which it has permissions. 该模拟用户将仅看到其拥有权限的服务器级视图和DMV的这些行。 See here and here for more info. 有关更多信息,请参见此处此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM