Home » Other » Client Tools » Output of a DB Query as Email using Powershell (Oracle Database Enterprise Server, 11.2.0.2.0, Windows 2008 Release 2)
Output of a DB Query as Email using Powershell [message #547549] Wed, 14 March 2012 12:11
kmsalih
Messages: 197
Registered: March 2006
Senior Member
Hello All,

Currently i am writing a code using powershell to query from Oracle Database 11g Release 2.

I got a code by searching google.

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
}

$connString = "password=assword;User ID=SYSTEM;Data Source=XE;Provider=OraOLEDB.Oracle"
$qry= "SELECT * FROM HR.DEPARTMENTS"
./Get-OLEDBData $connString $qry

is it required to create a DataSource using odbc32.cpl which points to the Oracle Database.

Also if you have a code for emailing the output of a query please post.

Thanks,
Salih KM
Previous Topic: Alternate solution to DB link
Next Topic: SQL tracker problem monitoring w3wp.exe
Goto Forum:
  


Current Time: Thu Mar 28 07:45:37 CDT 2024