Shutdown MSSQL server from perl script DBI

爱⌒轻易说出口 提交于 2019-12-02 17:21:37

问题


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.


回答1:


There's a SQL command called SHUTDOWN - more info here



来源:https://stackoverflow.com/questions/16338352/shutdown-mssql-server-from-perl-script-dbi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!