SQLCMD Via a Bat file.
net user ServiceLogAccount/add password
sqlcmd
DECLARE @HostName as nvarchar(20)
DECLARE @Login as nvarchar(40)
SET @HostName = (select host_name())
SET @Login = @HostName + '\ServiceLogAccount'
EXEC sp_grantlogin @Login
GO
EXIT
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
1>
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.
sqlcmd
DECLARE @HostName as nvarchar(20)
DECLARE @Login as nvarchar(40)
SET @HostName = (select host_name())
SET @Login = @HostName + '\ServiceLogAccount'
EXEC sp_grantlogin @Login
GO
EXIT
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
1>
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)
Please log in to answer
Posted by:
anonymous_9363
13 years ago
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, change
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, change
sqlcmd
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
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"
Jeeoo!
Santro
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"
Jeeoo!
Santro
Posted by:
anonymous_9363
13 years ago

so that the conversation will remain readable.