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   [ - ] Hide Comments


Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
Answer this question or Comment on this question for clarity


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.
Answered 04/16/2009 by: VBScab
Red Belt

Please log in to comment
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"

Answered 04/16/2009 by: zipsantro
Purple Belt

Please log in to comment

Please log in to comment