I know how to connect to an SQL Server database through a batch file, using this command for example:
sqlcmd -S <server_name> -U <user_name> -P <password>
But I would like to know if I could set these pieces of information like the server name, user name and password after being prompted for user input by the batch file.
This is what I have tried:
@echo off
set /p servernm="Enter server name: "
set /p usermn="Enter username: "
set /p dbpwd="Enter password: "
sqlcmd -h-1 -S %servernm% -U %usernm% -P %dbpwd% -i t_sql_select.sql -o t_sql_insert.sql
pause
I receive this error:
Sqlcmd: 'password': Unknown command. Enter '--help' for command help.Press any key to continue . . .
In this error, the “password” is the password that I entered after being prompted for the password input.
Does my approach make sense and is it even possible to connect to the database like that?