我需要从VBA上在Windows 11上运行Perl脚本。 perl脚本连接到远程计算机上的数据库。

问题描述 投票:0回答:0
我正在运行的perl脚本是:

use strict; use warnings; use DBI ; use DBD::Oracle ; my $SRV = "apsrV" ; my $DB = "db_v2"; my %attr = (PrintError => 1,RaiseError => 0); my $db; my $ResX1=eval{$db = DBI->connect("dbi:Oracle:$SRV/$DB", "user1", "pwordVal", \%attr)}; if(!$ResX1) { print "ERROR: db '$DB' on server '$SRV' does NOT exist or is not available." . "\n"; sleep(10); exit; } else { $db->{AutoCommit} = 0 ; $db->disconnect if defined($db) ; }

我从Excel VBA称其为命令:

dim perlcmdstr as string perlcmdstr = "perl C:\Users\userX\Connect_To_DB_1.pl" Call ShellWait(perlcmdstr, vbNormalFocus)

我假设当我打开命令提示符运行我的perl程序时,当我的vba代码调用相同的perl程序时,该命令提示正在设置。
对于信息,如果我在运行perl程序的命令提示符中键入'echo%oracle_home%',我将获得响应%oracle_home%,这意味着未设置oracle_home。
    

如果您使用Oracle DB驱动程序,则应使用此格式之一进行连接:
my $SRV = "apsrV"; 
my $DB = "db_v2";

# Correct DSN (choose based on your setup)
my $dsn = "dbi:Oracle:host=$SRV;port=1521;sid=$DB";  # If using SID
# my $dsn = "dbi:Oracle:host=$SRV;port=1521;service_name=$DB"; # If using Service Name
# my $dsn = "dbi:Oracle:$SRV";  # If using TNS

my %attr = (PrintError => 1, RaiseError => 1);
my $db;


vba windows perl
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.