我正在使用以下Power Shell代码从安装了HANA客户端的主机连接到HANA实例 -
function Get-OLEDBData ($connectstring, $sql) {
$OLEDBConn = New-Object System.Data.OleDb.OleDbConnection($connectstring)
$OLEDBConn.open()
$readcmd = New-Object system.Data.OleDb.OleDbCommand($sql,$OLEDBConn)
$readcmd.CommandTimeout = '300'
$da = New-Object system.Data.OleDb.OleDbDataAdapter($readcmd)
$dt = New-Object system.Data.datatable
[void]$da.fill($dt)
$OLEDBConn.close()
return $dt
}
$hdbSqlCmd = "myquery"
$hdbConnectionString = "Driver={HDBODBC};ServerNode=myserver:30015;UID=myuser;PWD=mypasswd;"
Get-OLEDBData $hdbConnectionString $hdbSqlCmd**
但我得到以下错误 -
New-Object : Exception calling ".ctor" with "1" argument(s): "An OLE DB Provider was not specified in the ConnectionString. An example would be, 'Provider=SQLOLEDB;'."
At C:\myspace\hana_connect_1.ps1:5 char:27+ $OLEDBConn = New-Object <<<< System.Data.OleDb.OleDbConnection($connectstring)
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
当我将连接字符串更改为Provider而不是Driver -
时 $hdbConnectionString = "Provider={HDBODBC};ServerNode=myserver:30015;UID=myuser;PWD=mypasswd;"
我得到以下错误 -
Exception calling "Open" with "0" argument(s): "The '{HDBODBC}' provider is not registered on the local machine."
At C:\myspace\hana_connect_1.ps1:6 char:19
+ $OLEDBConn.open <<<< ()
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException
即使我更改为32位驱动程序 - HDBODBC32,说明HDBODBC32未注册,错误仍然相同。
我现在迷路了,有人帮忙!!
答案 0 :(得分:0)
SAP HANA ODBC驱动程序不是OLEDB驱动程序。 因此,您必须使用ODBC API:
function Get-ODBCBData ($connectstring, $sql) {
$Conn = New-Object System.Data.odbc.ODBCconnection($connectstring)
$Conn.open()
$readcmd = New-Object system.Data.odbc.ODBCCommand($sql,$Conn)
$readcmd.CommandTimeout = '300'
...
$hdbConnectionString = "Driver={HDBODBC};ServerNode=myserver:30015;UID=myuser;PWD=mypasswd;"
Get-ODBCBData $hdbConnectionString $hdbSqlCmd**
应该有用。