Problem installing SQL and sqlcmd in the same .bat file

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

It seems that if sqlcmd is run from the same .bat file that started the installation, then sqlcmd fails with the following error: "sqlcmd" is not recognized as an internal or external command, operating program, or batch file. "

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

I do not want the user to run more than one .bat file, because this opens up problems with launching .bat files in the wrong order, by starting one and not the other, etc.

My two questions are:

  • Does anyone know why this is happening?
  • Is there a solution that involves running only one .bat file?
+4
source share
1 answer

I am afraid that I cannot be 100% sure of this problem, and I cannot add it to the comment, but I have to put it here.

1. Does anyone know why this is happening?

  • I would suggest that this happens because when you install SQL Server, it will add specific paths to the Windows environment variables. Since the script package is used to install the version of SQL Server, I would suggest that it does not update the Windows environment variables, which means that the SQLCMD.exe file contained in C: \ Program Files \ Microsoft SQL Server \ 100 \ Tools \ Binn \ (or if you install it, it is not cached).

2. Is there a solution that involves running only one .bat file?

  • If you set it default each time, for example, C: \ Program Files \ Microsoft SQL Server. Then you can just run SQLCMD right from there. I.e.

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

Perhaps you should create a variable for this path to simplify it.

I do not know the process from the script package to update or search for new Windows environment variables, however, I think this is a probable reason.

+5
source

All Articles