I'm writing a perl script in which I've to shutdown my mssql server ,do some operation and then I've to restart it.I know 1 way is to use netstat to stopt the service but I cann't use that. So I tried installing DBI and DBD::ODBC module.I'm able to connect and execute queries by following code
use DBI;
my $data_source = q/dbi:ODBC:AUTOMATION_WOW64/;
my $user = q/pa/;
my $password = q/DCE/;
# Connect to the data source and get a handle for that connection.
my $dbh = DBI->connect($data_source, $user, $password)
or die "Can't connect to $data_source: $DBI::errstr";
my $str=$dbh->prepare("select SERVERPROPERTY('edition')");
$str->execute();
my @row;
while (@row = $str->fetchrow_array) { # retrieve one row
print join(", ", @row), "\n";
}
but even after searching a lot I cann't find any query using whch I can shutdown my server. Just wanted to know is it possible to shutdown the server from sql query . I found one for mysql server
$rc = $dbh->func('shutdown', 'admin');
at this link http://metacpan.org/pod/DBD::mysql please tell me if something similar to this exist for mssql server.
There's a SQL command called SHUTDOWN
- more info here
来源:https://stackoverflow.com/questions/16338352/shutdown-mssql-server-from-perl-script-dbi