从Perl脚本DBI关闭MSSQL服务器 [英] Shutdown MSSQL server from perl script DBI
问题描述
我正在编写一个Perl脚本,其中我必须关闭mssql服务器,执行一些操作,然后重新启动它.我知道一种方法是使用netstat停止服务,但我不能使用它. 因此,我尝试安装DBI和DBD :: ODBC模块.我能够通过以下代码连接并执行查询
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";
}
但是即使搜索了很多我都无法使用可以关闭服务器的任何查询. 只想知道是否可以从sql query关闭服务器. 我找到了一个用于mysql服务器的
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');
在此链接 http://metacpan.org/pod/DBD::mysql 请告诉我mssql服务器是否存在与此类似的内容.
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
这篇关于从Perl脚本DBI关闭MSSQL服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!