{"id":528,"date":"2015-04-28T10:05:59","date_gmt":"2015-04-28T07:05:59","guid":{"rendered":"http:\/\/www.ersinakyuz.com\/?p=528"},"modified":"2016-07-13T15:45:20","modified_gmt":"2016-07-13T12:45:20","slug":"how-to-connect-oracle-db-with-powershell","status":"publish","type":"post","link":"https:\/\/www.ersinakyuz.com\/?p=528","title":{"rendered":"How to connect Oracle DB with PowerShell"},"content":{"rendered":"<pre class=\"lang:default decode:true\"># Load the ODP assembly \r\n[Reflection.Assembly]::LoadFile(\"C:\\oracle\\11.2.0\\client_2\\odp.net\\bin\\4\\Oracle.DataAccess.dll\")|Out-Null<\/pre>\n<pre class=\"lang:default decode:true\"># \r\n#vars&amp;cons\r\n$stations =@{\r\n\"424\"=\"Istanbul\";\r\n\"421\"=\"\u0130zmir\"\r\n}\r\n$dbuser=\"user\"\r\n$dbpasswd=\"password\"\r\n<\/pre>\n<p>connect to Oracle<\/p>\n<pre class=\"lang:default decode:true \">\r\n\r\n$constr =\r\n\"\r\nUser Id=$dbuser;\r\nPassword=$dbpasswd;\r\nData Source=CITIES\r\n\"\r\n$conn= New-Object Oracle.DataAccess.Client.OracleConnection($constr)\r\n$conn.Open()\r\n<\/pre>\n<p>Create a datareader for a SQL statement<\/p>\n<pre class=\"lang:default decode:true \">\r\n$sql=\"select stationid\r\nfrom CITIES.SWITCHPARAMETER\r\nwhere switchid = '2'\r\n\"\r\n$command = New-Object Oracle.DataAccess.Client.OracleCommand( $sql,$conn)\r\n$reader=$command.ExecuteReader()\r\n<\/pre>\n<p>Write out the results<\/p>\n<pre class=\"lang:default decode:true \"># \r\nwhile ($reader.read()) {\r\n$stationID=$reader.GetString(0)\r\n$stationname=$stations.Get_Item($stationID)\r\nWrite-Host\r\n\"\r\nStation ID: $stationID ($stationname)\"\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p># Load the ODP assembly [Reflection.Assembly]::LoadFile(&#8220;C:\\oracle\\11.2.0\\client_2\\odp.net\\bin\\4\\Oracle.DataAccess.dll&#8221;)|Out-Null # #vars&amp;cons $stations =@{ &#8220;424&#8221;=&#8221;Istanbul&#8221;; &#8220;421&#8221;=&#8221;\u0130zmir&#8221; } $dbuser=&#8221;user&#8221; $dbpasswd=&#8221;password&#8221; connect to Oracle $constr = &#8221; User Id=$dbuser; Password=$dbpasswd; Data Source=CITIES &#8221; $conn= New-Object Oracle.DataAccess.Client.OracleConnection($constr) $conn.Open() Create a datareader for a SQL statement $sql=&#8221;select stationid from CITIES.SWITCHPARAMETER where switchid = &#8216;2&#8217; &#8221; $command = New-Object Oracle.DataAccess.Client.OracleCommand( $sql,$conn) $reader=$command.ExecuteReader() Write out &#8230; <a title=\"How to connect Oracle DB with PowerShell\" class=\"read-more\" href=\"https:\/\/www.ersinakyuz.com\/?p=528\" aria-label=\"Read more about How to connect Oracle DB with PowerShell\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27,7],"tags":[24,23],"class_list":["post-528","post","type-post","status-publish","format-standard","hentry","category-powershell","category-programming","tag-oracle","tag-powershell"],"_links":{"self":[{"href":"https:\/\/www.ersinakyuz.com\/index.php?rest_route=\/wp\/v2\/posts\/528","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ersinakyuz.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ersinakyuz.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ersinakyuz.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ersinakyuz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=528"}],"version-history":[{"count":10,"href":"https:\/\/www.ersinakyuz.com\/index.php?rest_route=\/wp\/v2\/posts\/528\/revisions"}],"predecessor-version":[{"id":547,"href":"https:\/\/www.ersinakyuz.com\/index.php?rest_route=\/wp\/v2\/posts\/528\/revisions\/547"}],"wp:attachment":[{"href":"https:\/\/www.ersinakyuz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ersinakyuz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ersinakyuz.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}