如何使用 nowait 使 raiserror 与 sqlcmd 一起工作? [英] how to make raiserror with nowait work with sqlcmd?

查看:40
本文介绍了如何使用 nowait 使 raiserror 与 sqlcmd 一起工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是命令行:

sqlcmd -S localhost -U myuser -P mypwd -b -r0 -Q "raiserror('hello',10,1) with nowait;waitfor delay '00:00:10';raiserror('world!',10,1) with nowait"

它应该立即输出hello,然后在 10 秒后输出 world!.不幸的是,它在 10 秒后输出了两个字符串.

It is supposed to output hello immediately and then after 10 seconds world!. Unfortunately, it outputs both strings after 10 seconds.

sqlcmd 能做对吗?怎么样?

Can sqlcmd do it right? How?

附言

我不想为此使用 LinqPad 或任何 GUI.

I do not want to use LinqPad or any GUI for that matter.

推荐答案

我意识到这是一篇旧帖子,很有可能没有人会看到我的答案,但我会提供我们在我的组织中所做的一些事情.我会第一个承认这有点混乱,但它对我们来说一直很好.

I realize this is an old post and there is a high probability that no one will see my answer, but I'll offer something we did at my organization. I'll be the first to admit it's a bit of a kludge, but it has been working well for us.

我们有通过 SQLCMD 调用的进程,它们使用 Raiserror 来指示进度条目.很明显,当我们很久以前升级到 Sql 2012 时,这不再有效.

We have processes that are invoked via SQLCMD and they use Raiserror to indicate progress entries. Obviously that no longer worked when we upgraded to Sql 2012 a long time ago.

我最终在 C 驱动器上创建了一个名为 c:\Sql2008_SQLCMD 的新目录,并将以下两个文件从 Sql Server binn 文件夹的 Sql 2008 安装复制到该文件夹​​.

I wound up creating a new directory on my C-drive called c:\Sql2008_SQLCMD and I copied the following two files from a Sql 2008 install of Sql Server binn folder to that folder.

  • SQLCMD.EXE
  • SQLCMD.rll

然后我修改了我的进程(在 bat 文件中)以使用这样的 dos 变量

I then modified my processes (in bat files) to use a dos variable like this

SET SQLCMD="C:\Sql2008_SQLCMD\sqlcmd"

然后我用

%SQLCMD% -S 等等……

%SQLCMD% -S blah...

代替正常

SQLCMD -S 等等

SQLCMD -S blah

这种技术使我能够调用 SQLCMD 的 SQL 2008 版本,而对我的 bat 文件脚本进行最少的更改.

This technique allowed me to invoke the SQL 2008 version of SQLCMD with a minimum of changes to my bat files scripts.

这让我可以继续查看 Raiserror 的输出,以便查看我的进程的进度.

This allowed me to continue to see the output from Raiserror so I could see the progress of my processes.

我目前仍在 Sql 2016 CU3 下使用此技术 - 我不确定当我们最终使用 Sql 2017 或以后是否会遇到任何问题

I'm currently still using this technique under Sql 2016 CU3 - I'm not sure if I'll have any problems when we eventually go to Sql 2017 or beyound

这篇关于如何使用 nowait 使 raiserror 与 sqlcmd 一起工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆