首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

powershell 运行脚本出错,该如何处理

2012-02-11 
powershell 运行脚本出错,........@$anError $false[Reflection.Assembly]::LoadFile($psh + \dll\Or

powershell 运行脚本出错,
........

'@

$anError = $false;

[Reflection.Assembly]::LoadFile($psh + "\dll\Oracle.DataAccess.dll")

$conn= New-Object Oracle.DataAccess.Client.OracleConnection($oracleConstr);
$conn.Open();

#the first thing is lookup connection information for VCenter Server:
$sql = "SELECT sc.scsystem, sc.scIP, sc.scAccount, sc.scPassword FROM SystemConfigure sc WHERE sc.scsystem = 'vcenter'" + 
" OR sc.scsystem = 'firewall'" +
" OR sc.scsystem = 'unix command gateway'" ;

$vcenter = $null;
$unixServer = $null;
$firewall = $null;

.........


此脚本是在windows2003虚拟机里运行的,功能是用来产出虚拟机的,调用脚本执行。powershell脚本连接oracle数据库是ok的,调用dll\Oracle.DataAccess.dll文件也没有问题,但是连接后,走到$conn.Open()的时候报如下的错误。各位大虾看到后说下原因,在线跪求。。。

GAC Version Location  
--- ------- --------  
True v2.0.50727 C:\WINDOWS\assembly\GAC_32\Oracle.DataAccess\2.102.2.20__89b483f429c47342\Oracle.DataAccess.dll  
Exception calling "Open" with "0" argument(s): ""
At E:\powerShellScript\CreateVirtualMachineByVMOrderID.ps1:71 char:11
+ $conn.Open <<<< ();
  + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
  + FullyQualifiedErrorId : DotNetMethodException
 

[解决办法]
上午在oracle 11g上碰到了点别的问题,搞定了,代码如下:

功能:连接oracle查询表并显示表记录,显示字段描述:

Python code
# Load the ODP assembly [Reflection.Assembly]::LoadFile("C:\oracle\product\11.2.0\dbhome_1\ODP.NET\bin\2.x\Oracle.DataAccess.dll")#connect to Oracle $constr = "User Id=scott;Password=1111111;Data Source=orcl"$conn= New-Object Oracle.DataAccess.Client.OracleConnection($constr)$conn.Open()# Create a datareader for a SQL statement $sql="select deptno,dname,loc from dept"$command = New-Object Oracle.DataAccess.Client.OracleCommand( $sql,$conn)$reader=$command.ExecuteReader()#loop through recordsetwhile ($reader.read()){    #assign variables from recordset    $objdeptno=$reader.GetInt16(0)    $objdname=$reader.GetString(1)    $objloc=$reader.GetString(2)        Write-Host $objdeptno    Write-Host $objdname    Write-Host $objloc    Write-Host "====="}# Write out the result set structure Write-Host "fields:====="for ($i=0;$i -lt $reader.FieldCount;$i++) {    Write-Host  $reader.GetName($i) $reader.GetDataTypeName($i) }$conn.Close() 

热点排行