SQLCMD Via a Bat file.

net user ServiceLogAccount/add password
DECLARE @HostName as nvarchar(20)
DECLARE @Login as nvarchar(40)
SET @HostName = (select host_name())
SET @Login = @HostName + '\ServiceLogAccount'
EXEC sp_grantlogin @Login

Hi all,
I am desparate now. I need some help in executing the above code using a bat file. All it does it run a stored procedure against a user "ServiceLogAccount". When I paste this into Command Promp screen it runs swimmingly. BUT when I copy the above into a notepad and save as "RunMe.bat", and then run it, the following is displayed.

C:\Documents and Settings\Administrator\Desktop>SQLCMD

And the cursor just waits at 1>.
So HOW do I get this to run in a bat file??

Any help on this will be appreciated. It has to run in a .bat file, as its part of an automated process.

0 Comments   [ + ] Show comments

Answers (3)

Posted by: anonymous_9363 13 years ago
Red Belt
Quite what this has to do with MSI package development escapes me but, anyway...

I've never used SQLCMD but, if experience with similar tools is anything to go by, how about prefixing each line with a call to SQLCMD? That is, changesqlcmd
DECLARE @HostName as nvarchar(20)
DECLARE @Login as nvarchar(40)
tosqlcmd DECLARE @HostName as nvarchar(20)
sqlcmd DECLARE @Login as nvarchar(40)
and so on.
Posted by: zipsantro 13 years ago
Purple Belt
Instead of using a batch file you can OSQL.exe in your custom action.
This can be found under C:\Program Files\Microsoft SQL Server\80\Tools\Binn\OSQL.EXE

This is SQL Server exe and doesn't need login credentials to connect and perform task on database. This can execute SQL files, stored procedures, etc.

Custom Action Type = 3106 (Execute Program From Destination)
SourceDir = SqlCommonBinn
Target = osql.exe -E -S <SQLSERVER>\<SQLINSTANCE> -Q "<STOREDPROC> <DatabaseName>, <>Parameters=<value>" -o "%TEMP%\temp.log"

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login


This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ