nagaraju
6th July 2006 06:12 UTC
Executing multiple commands at a time...
Hi,
I am trying to attach a database to SQLServer using NSIS. Here i am using nsExec::ExecToLog
This is the actual scenario in command prompt...
C:\>osql -E -S 'ServerName'
1> exec sp_attach_db @dbname = 'SnapCatalog',
2> @filename1 = 'File_Data.mdf',
3> @filename2 = 'File_Log.ldf'
4> go
1> quit
After running "osql -E -S 'ServerName'" command, i will be prompted to "1>" where i need to enter "exec sp_attach_db @dbname = 'SnapCatalog'," and upon hitting enter i will be prompted to "2>" and i need to enter the next statement... and so on.
When i am using NSIS to run the same, i am using...
nsExec::ExecToLog 'cmd /c .... '
But this doesnt execute as its not directing to "1>" after executing "osql -E -S 'ServerName'", but infact pointing back to command prompt to run the next line.
I will be pretty much pleased if someone can help me out on cracking this puzzle.
Thanking in advance !
Afrow UK
6th July 2006 10:05 UTC
Is there no way to specify these commands as parameters?
-Stu
Takhir
6th July 2006 10:44 UTC
Sometimes ExecCmd or ExecDos can do the trick.
Mr Inches
6th July 2006 14:33 UTC
Try this:
Create a text file called 'TSCMDS.DAT' with lines like so:
exec sp_attach_db @dbname = 'SnapCatalog',
@filename1 = 'File_Data.mdf',
@filename2 = 'File_Log.ldf'
go
quit
<blank line>
and then run this command through one of the Exec commands (assuming that osql is available via the PATH):
"osql -E -S 'ServerName" -i "TSCMDS.DAT"
You can also use the '-o <filename>' switch to capture the output of your sequence of commands.
For more information, this link may help:
<url>http://www.di-mgt.com.au/osqlUtility.htm/url>
Duncan
nagaraju
7th July 2006 05:46 UTC
Hi,
Thanks a lot for the response i got from u.
I am sure the solution you gave me would definitely resolve the issue.
I have tried with a simialr option and that worked fine. I have used the following command in nsis script...
nsExec::ExecToLog 'cmd /c osql -U $3 -P $4 -S $1 -Q
$\"exec sp_attach_db @dbname = $\'SnapCatalog$\',
@filename1 = $\'$2\Data\SnapCatalog_Data.mdf$\',
@filename2 = $\'$2\Data\SnapCatalog_Log.ldf$\'$\"'
The difference is i have tried with -Q (command line query) and the one you have tried upon is -i (input file).
I appreciate your time and response.
Thank you !