SQL install和sqlcmd在同一个.bat文件中出现问题(Issue with SQL install and sqlcmd in same .bat file)

编程入门 行业动态 更新时间:2024-10-28 09:18:21
SQL install和sqlcmd在同一个.bat文件中出现问题(Issue with SQL install and sqlcmd in same .bat file)

我正在尝试使用单个.bat文件:1)在Windows 7 Professional 64位计算机上从SQLEXPR_x64_ENU.exe安装SQL Server 2008 R2 Express,以及2)安装完成后运行一些.sql脚本。

似乎如果sqlcmd从运行安装的同一.bat文件运行,则sqlcmd失败并出现以下错误:“'sqlcmd'未被识别为内部或外部命令,可运行程序或批处理文件。”

如果install和.sql脚本是从单独的.bat文件运行的,那么我没有问题(所以我知道问题不在于sqlcmd语法)。 我尝试使用单个.bat并在新窗口中运行sqlcmd命令(启动cmd / c“sqlcmd ...”)并从原始.bat文件中调用包含sqlcmd命令的第二个.bat文件( \ filepath \ file.bat)但在每种情况下都会出现相同的错误。

我不希望用户必须启动多个.bat文件,因为这会导致以错误的顺序运行.bat文件,运行一个但不运行另一个等的问题等。

我的两个问题是:

有谁知道为什么会这样? 是否有解决方案只涉及启动单个.bat文件?

I am trying to use a single .bat file to: 1) install SQL Server 2008 R2 Express from SQLEXPR_x64_ENU.exe on Windows 7 Professional 64-bit machines, and 2) run some .sql scripts once the install is complete.

It appears that if sqlcmd is run from the same .bat file that ran the install, then sqlcmd fails with the following error: "'sqlcmd' is not recognized as an internal or external command, operable program or batch file."

If the install and .sql scripts are run from separate .bat files, then I have no issues (and so I know that the problem is not with the sqlcmd syntax). I have tried using a single .bat and running the sqlcmd commands in a new window (start cmd /c "sqlcmd ...") and calling a second .bat file, containing the sqlcmd commands, from within the original .bat file (\filepath\file.bat) but the same error occurs in each case.

I don't want the user to have to launch more than one .bat file because that opens up problems of running the .bat files in the wrong order, running one but not the other, etc.

My two questions are:

Does anyone know why this is happening? Is there a solution that involves launching a single .bat file only?

最满意答案

我担心我不能100%肯定这个问题,我不能把它添加到评论中,所以我必须把它放在这里。

1.有谁知道为什么会这样?

我想象一下这种情况正在发生,因为当您安装SQL Server时,它将添加到Windows环境变量的特定路径。 由于批处理脚本用于安装SQL Server版本,我猜它不会刷新Windows环境变量,这意味着C:\ Program Files \ Microsoft SQL Server \ 100 \ Tools \ Binn \中包含的SQLCMD.exe文件(或者,无论您安装它,都不会缓存)。

2.有解决方案只涉及启动单个.bat文件吗?

如果每次都将其安装到默认位置,例如C:\ Program Files \ Microsoft SQL Server。 然后你可以直接从那里启动SQLCMD。 IE

C:\ Program Files \ Microsoft SQL Server \ 100 \ Tools \ Binn \ SQLCMD.exe -q等....

您可能值得为该路径创建变量以使其更容易。

我不知道从批处理脚本刷新或寻找新的Windows环境变量的过程,但是我想象的可能是原因。

I'm afraid I cannot be 100% sure on this issue and I cannot add it to a comment yet so I have to put it here.

1.Does anyone know why this is happening?

I'd Imagine this is happening because when you install SQL Server it will add specific paths to the Windows Environment Variables. As the batch script is used to install the SQL Server edition I would guess that it is not refreshing the Windows Environment Variables, meaning that the SQLCMD.exe file contained within C:\Program Files\Microsoft SQL Server\100\Tools\Binn\ (Or whereever you are installing it is not cached).

2.Is there a solution that involves launching a single .bat file only?

If you are installing it to a default location each time, for instance the C:\Program Files\Microsoft SQL Server. Then you might be able to just launch the SQLCMD straight from there. I.E.

C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.exe -q etc....

You might be worth creating a variable to that path to make it easier.

I don't know of a process from a batch script to refresh or look for new Windows Environment Variables, however that i'd imagine is the likely cause.

更多推荐

本文发布于:2023-08-06 07:19:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1445981.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   在同一个   sqlcmd   install   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!