使用 SqlCmd 的 Powershell 调用表达式

发布于 2024-09-15 04:35:39 字数 423 浏览 3 评论 0原文

当使用 Invoke-Expression sqlcmd -i script.sql 时,它似乎只显示返回的前两行。

当我在查询分析器中运行脚本时,它返回:

(2 rows affected)
Changed database context to 'ShopStore'.
(5 rows affected)
Changed database context to 'ShopStore'.

但是从 PowerShell 我只得到:

(2 rows affected)
Changed database context to 'ShopStore'.

YET,整个事情正在运行,我可以通过处理结果来看到这一点。这是为什么呢?

When using Invoke-Expression sqlcmd -i script.sql it seems to only display the first 2 lines returned.

When I run in Query Analyser the script it returns:

(2 rows affected)
Changed database context to 'ShopStore'.
(5 rows affected)
Changed database context to 'ShopStore'.

However from PowerShell I only get:

(2 rows affected)
Changed database context to 'ShopStore'.

YET, the whole thing is being run, I can see this by playing with results. Why is this?

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

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

发布评论

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

评论(1

温暖的光 2024-09-22 04:36:13

sqlcmd.exe 上的文档:

SQL Server Management Studio 使用
Microsoft.NET FrameworkSqlClient 用于
常规和SQLCMD模式执行
在查询编辑器中。当 sqlcmd 运行时
在命令行中,sqlcmd 使用
OLE DB 提供程序。因为不同
默认选项可能适用,您可能
当你看到不同的行为
在 SQL Server 中执行相同的查询
SQLCMD 模式下的 Management Studio 和
在 sqlcmd 实用程序中。

这可能就是你看到不同结果的原因吗?

From the docs on sqlcmd.exe:

SQL Server Management Studio uses the
Microsoft.NET FrameworkSqlClient for
execution in regular and SQLCMD mode
in Query Editor. When sqlcmd is run
from the command line, sqlcmd uses the
OLE DB provider. Because different
default options may apply, you might
see different behavior when you
execute the same query in SQL Server
Management Studio in SQLCMD Mode and
in the sqlcmd utility.

Could this be why you're seeing different results??

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