在数据库级别设置 NOCOUNT OFF?

发布于 2024-09-11 03:05:07 字数 313 浏览 2 评论 0原文

我可以将特定数据库的 NOCOUNT 默认设置为 OFF 吗?

我需要它用于 NHibernate(如果它打开,我在保存时会遇到异常)。我可以看到为整个服务器禁用它的设置(它被设置为ON),但我们正在与其他数据库共享该服务器。有没有办法只为我的数据库将其设置为“关闭”?

或者是否有 NHibernate 设置可以为我完成此操作? (我现在已经使用自定义的 DriverConnectionProvider 来解决这个问题,每当创建连接时都会发出命令。工作正常,但感觉有点尴尬)

顺便说一句,我正在使用 SQL Server 2000。

谢谢 马特

Can I set NOCOUNT to be OFF by default for a particular database?

I need it for NHibernate (if it's ON, I get exceptions when saving). I can see the setting to disable it for an entire server (where it's set ON), but we're sharing the server with other databases. Is there a way I can set it to OFF just for my database?

Or is there an NHibernate setting that will do this for me? (I've worked around it for now with a custom DriverConnectionProvider that issues the command whenever it creates a connection. Works ok, but feels a bit awkward)

I'm using SQL Server 2000, btw.

Thanks
Matt

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

入画浅相思 2024-09-18 03:05:07

不,SET NOCOUNT 没有数据库范围的设置。

同样的问题: http://www.eggheadcafe.com/software/aspnet /32120672/set-nocount.aspx

no, there is no database wide setting for SET NOCOUNT.

same question: http://www.eggheadcafe.com/software/aspnet/32120672/set-nocount.aspx

浪荡不羁 2024-09-18 03:05:07

您可以使用 NH IInterceptor 接口的 OnPrepareStatement 方法来修改 NH 生成的 SQL 语句,以在您发出的每个 sql 查询的顶部包含一个“set nocount off”语句。应用。

一些叫 Dave 的家伙认为这是“邪恶的” “这样做,但这可能是你的答案。该链接会将您带到他的博客上描述如何实现它的页面。

我对此的保留意见是,您将创建对运行在理解“set nocount off”的数据库服务器上的应用程序的依赖关系 - 换句话说,您将忽略配置的方言。

You could use the NH IInterceptor interface's OnPrepareStatement method to modify the NH-generated SQL statements to include a "set nocount off" statement at the top of every sql query issued by your application.

Some bloke called Dave reckons it's "evil" to do so, but it might be your answer. The link takes you to the page on his blog describing how to implement it.

My reservation about doing so is you would be creating a dependency on your application running against a database server that understands "set nocount off" - in other words, you'd be ignoring the configured dialect.

吃素的狼 2024-09-18 03:05:07

您也可以从 SSMS 设置数据库的 nocount 属性 ON/OFF。请在下面找到 “在此处输入图像描述”"

  1. 右键单击​​实例并选择属性
  2. 然后选择连接
  3. 在右侧窗格中,您将找到包括“无计数”在内的属性列表
  4. 取消选中此属性以将其关闭

You can set nocount property of database ON/OFF from SSMS as well. Please find below enter image description here

  1. Right click on instance and select properties
  2. Then select Connections
  3. On right pane, you will find list of properties including 'no count'
  4. Uncheck this property to make it OFF
不爱素颜 2024-09-18 03:05:07

设置 NOCOUNT 是在数据库级别设置的。分别依次执行以下查询。这提供了更好的想法。

SET NOCOUNT ON 
Update Users set FirstName='XXXX' where Id='YYYY'; 

***命令成功完成。

SET NOCOUNT OFF
Update Users set FirstName='XXXX' where Id='YYYY'; 

***(1 行受影响)

Set NOCOUNT is Set at DB level. Execute below queries one after another separately. This gives better idea.

SET NOCOUNT ON 
Update Users set FirstName='XXXX' where Id='YYYY'; 

***Command(s) completed successfully.

SET NOCOUNT OFF
Update Users set FirstName='XXXX' where Id='YYYY'; 

***(1 row(s) affected)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文