Jump to content

Recommended Posts

Posted (edited)

Hey all,

I wrote a script to backup a MS SQL database and some files to another directory.

My question is how is it possible to wait until the MS SQL service is stopped before continuing the script and copying the database and the other files.

I tried to realize this with a while loop but i doesn't work.

This is the part of the script which doesn't want to work as I want it to:

;Shutdown SQL-Server
_RunDOS("sc stop " & $sqlinstancename)

$statusservice = _Service_QueryStatus($sqlinstancename)
While $statusservice[1] <> 1
 Sleep(5000)
WEnd

For the function _Service_QueryStatus I use the UDF Services.au3, the function returns 1 for Array[1] if service is stopped. If Service isn't stopped I want the script to wait five seconds until rechecking the state.

But this doesn't work :)

Thanks for help.

Jass

Edited by Jass
Posted (edited)

The easiest i can thing of is to use RunWait to stop the service .

@edit

Scratch that it doesnt work - the CMD command doesnt wait until the service is stopped to complete and exit.

Edited by Juvigy
Posted (edited)

Hi,

you have to refresh the $statusservice in between the While loop, otherwise it won't change and loop for ever:

$statusservice = _Service_QueryStatus($sqlinstancename)
While $statusservice[1] <> 1
   Sleep(5000)
   $statusservice = _Service_QueryStatus($sqlinstancename)
WEnd

;-))

Stefan

Edited by 99ojo
Posted

Hi,

you have to refresh the $statusservice in between the While loop, otherwise it won't change and loop for ever:

;-))

Stefan

Great!

Thanks man und schöne Grüße nach Bonn :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...