Share via


connect DB through BAT file

Question

Tuesday, June 24, 2014 10:26 AM

set /p SName=Server Name :
set /p UName=User Name :
set /p Pwd=Password :
set /p DbName=Database Name :

Can i set permanently or one time above details in batch file instead of given again and again while we execute the batch file to execute the DB scripts

All replies (2)

Tuesday, June 24, 2014 3:29 PM ✅Answered | 1 vote

Did you try using sqlcmd? You can pass credentials  and execute the sql file. 

for example

C:\Program Files\Microsoft SQL Server\100\Tools\Binn>SQLCMD.EXE -S hqdbsp18 -i " C:\TestCmd.sql" -d "master" -U xyz -P abcd1234

http://technet.microsoft.com/en-us/library/ms165702(v=sql.105).aspx

--Prashanth


Tuesday, June 24, 2014 2:47 PM

Hi Rao,

What is your attempt to do here? The brief description that is there, is insufficient to understand the issue.

Please mark the answer as helpful if i have answered your query. Thanks and Regards, Kartar Rana