{"id":509,"date":"2015-10-06T07:30:45","date_gmt":"2015-10-06T07:30:45","guid":{"rendered":"http:\/\/www.dbafox.com\/?p=509"},"modified":"2018-09-18T06:59:11","modified_gmt":"2018-09-18T05:59:11","slug":"openrowset-query-oracle-sql-server-using-linked-server","status":"publish","type":"post","link":"https:\/\/dbafox.com\/?p=509","title":{"rendered":"OPENROWSET &#8211; Query Oracle from SQL Server using a linked server"},"content":{"rendered":"<h2>Query Oracle from SQL Server using a linked server<\/h2>\n<p>This post describes the basics of querying an Oracle database from Microsoft SQL Server.<\/p>\n<p>Oracle data can be queried from SQL Server via a linked server defined in Microsoft SQL Server<\/p>\n<h3>Install oracle client on the SQL Server Database Machine<\/h3>\n<p>The Oracle client is required to expose the OraOLEDB Oracle provider and for subsequent connections to Oracle databases via OracleNet &#8211; Oracle transparent network substrate (tnsnames etc.)&lt;\/p<\/p>\n<h3>Create an entry for the Oracle database in the tnsnames.ora Oracle Net File<\/h3>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nORCL=(DESCRIPTION =  (ADDRESS = (PROTOCOL = TCP)(HOST = oracle_server)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED)   (SERVICE_NAME = ORCL)))\r\n<\/pre>\n<h3>Create a linked server in SQL Server<\/h3>\n<pre class=\"brush: tsql; title: ; notranslate\" title=\"\">\r\nUSE &#x5B;master]\r\nGO\r\nEXEC master.dbo.sp_addlinkedserver @server = N'ORCL', @srvproduct=N'Oracle', @provider=N'OraOLEDB.Oracle', @datasrc=N'ORCL'\r\nGO\r\nEXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'ORACLE_ORCL',@useself=N'False',@locallogin=NULL,@rmtuser=N'orcl_user',@rmtpassword='orcl_pwd'\r\nGO\r\n<\/pre>\n<h3>Query the Oracle data<\/h3>\n<p>Grant the Oracle user &#8220;select any dictionary&#8221; privileges for test purposes. oracle data can be queried using &#8220;openrowset&#8221; or directly in a SQL statement using the linked server<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\n-- using openrowset\r\nselect * from openrowset('OraOLEDB.Oracle','ORCL';'orcl_user';'orcl_pwd','select * from dual')\r\n\r\n-- direct sql using &#x5B;&amp;lt;LINKED_SERVER&amp;gt;]..&#x5B;OWNER].&#x5B;OBJECT_NAME]\r\nselect * from &#x5B;ORCL]..&#x5B;SYS].&#x5B;DUAL]\r\n<\/pre>\n<h3>Provider Properties<\/h3>\n<p>SQL queries can be executed &#8220;inprocess&#8221; or not &#8220;inprocess&#8221;.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1246\" src=\"https:\/\/dbafox.com\/wp-content\/uploads\/provider_properties.png\" alt=\"\" width=\"240\" height=\"200\" srcset=\"https:\/\/dbafox.com\/wp-content\/uploads\/provider_properties.png 240w, https:\/\/dbafox.com\/wp-content\/uploads\/provider_properties-150x125.png 150w\" sizes=\"auto, (max-width: 240px) 100vw, 240px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1243\" src=\"https:\/\/dbafox.com\/wp-content\/uploads\/inprocess-300x139.png\" alt=\"\" width=\"300\" height=\"139\" srcset=\"https:\/\/dbafox.com\/wp-content\/uploads\/inprocess-300x139.png 300w, https:\/\/dbafox.com\/wp-content\/uploads\/inprocess-150x69.png 150w, https:\/\/dbafox.com\/wp-content\/uploads\/inprocess.png 644w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>&#8220;inprocess&#8221; may cause sql server crash if there are issues with the provider, so it is recommended to execute &#8220;out of process&#8221;. To run &#8220;out of process&#8221;, permissons are required on the MSDAINITIALIZE DCOM component, to initialize the provider.<\/p>\n<h4>Run dcomcnfg from cmd<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1241\" src=\"https:\/\/dbafox.com\/wp-content\/uploads\/dcomcnfg_cmd.png\" alt=\"\" width=\"263\" height=\"123\" srcset=\"https:\/\/dbafox.com\/wp-content\/uploads\/dcomcnfg_cmd.png 263w, https:\/\/dbafox.com\/wp-content\/uploads\/dcomcnfg_cmd-150x70.png 150w\" sizes=\"auto, (max-width: 263px) 100vw, 263px\" \/><\/p>\n<h4>Navigate to MSDAINITIALIZE component<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1242\" src=\"https:\/\/dbafox.com\/wp-content\/uploads\/dcomconfig-300x111.png\" alt=\"\" width=\"300\" height=\"111\" srcset=\"https:\/\/dbafox.com\/wp-content\/uploads\/dcomconfig-300x111.png 300w, https:\/\/dbafox.com\/wp-content\/uploads\/dcomconfig-150x55.png 150w, https:\/\/dbafox.com\/wp-content\/uploads\/dcomconfig.png 667w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1244\" src=\"https:\/\/dbafox.com\/wp-content\/uploads\/msda_props-226x300.png\" alt=\"\" width=\"226\" height=\"300\" srcset=\"https:\/\/dbafox.com\/wp-content\/uploads\/msda_props-226x300.png 226w, https:\/\/dbafox.com\/wp-content\/uploads\/msda_props-113x150.png 113w, https:\/\/dbafox.com\/wp-content\/uploads\/msda_props.png 409w\" sizes=\"auto, (max-width: 226px) 100vw, 226px\" \/><\/p>\n<p>Edit the permissions to allow groups or specific users to use the provider according to your requirements.<\/p>\n<h3>Ad-Hoc Distributed Queries<\/h3>\n<p>If there is an error reported when the &#8220;openrowset&#8221; sql statement is executed, as follows:<\/p>\n<pre class=\"\">Msg 15281, Level 16, State 1, Line 3\r\nSQL Server blocked access to STATEMENT 'OpenRowset\/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure. For more information about enabling 'Ad Hoc Distributed Queries', search for 'Ad Hoc Distributed Queries' in SQL Server Books Online.<\/pre>\n<p>The use of &#8216;Ad Hoc Distributed Queries&#8217; can be enabled by an administrator as decribed im the error message.<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nsp_configure 'Ad Hoc Distributed Queries',1  \r\nreconfigure \r\n<\/pre>\n<p>Or use SSMS GUI, right-click on instance, select Facets, navigate to the &#8220;Surface Area Configuraion in the Facet drop-down list, and set Facet property &#8220;AdHocRemoteQueriesEnabled&#8221; to true&#8221;<\/p>\n<h3>Add User to DCOM Users Group<\/h3>\n<h2><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-1332\" src=\"https:\/\/dbafox.com\/wp-content\/uploads\/DCOM_Users_group-300x170.png\" alt=\"\" width=\"457\" height=\"259\" srcset=\"https:\/\/dbafox.com\/wp-content\/uploads\/DCOM_Users_group-300x170.png 300w, https:\/\/dbafox.com\/wp-content\/uploads\/DCOM_Users_group-150x85.png 150w, https:\/\/dbafox.com\/wp-content\/uploads\/DCOM_Users_group.png 745w\" sizes=\"auto, (max-width: 457px) 100vw, 457px\" \/><\/h2>\n<p>&nbsp;<\/p>\n<h3><\/h3>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Query Oracle from SQL Server using a linked server This post describes the basics of querying an Oracle database from Microsoft SQL Server. Oracle data can be queried from SQL Server via a linked server defined in Microsoft SQL Server &hellip; <a href=\"https:\/\/dbafox.com\/?p=509\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"pgc_sgb_lightbox_settings":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[24,28],"tags":[],"class_list":["post-509","post","type-post","status-publish","format-standard","hentry","category-ms-sql-server","category-oracle-technical"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>OPENROWSET - Query Oracle from SQL Server using a linked server - dbafox<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/dbafox.com\/?p=509\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"OPENROWSET - Query Oracle from SQL Server using a linked server - dbafox\" \/>\n<meta property=\"og:description\" content=\"Query Oracle from SQL Server using a linked server This post describes the basics of querying an Oracle database from Microsoft SQL Server. Oracle data can be queried from SQL Server via a linked server defined in Microsoft SQL Server &hellip; Continue reading &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/dbafox.com\/?p=509\" \/>\n<meta property=\"og:site_name\" content=\"dbafox\" \/>\n<meta property=\"article:published_time\" content=\"2015-10-06T07:30:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-09-18T05:59:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/dbafox.com\/wp-content\/uploads\/provider_properties.png\" \/>\n<meta name=\"author\" content=\"Ray Fox\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ray Fox\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/dbafox.com\/?p=509\",\"url\":\"https:\/\/dbafox.com\/?p=509\",\"name\":\"OPENROWSET - Query Oracle from SQL Server using a linked server - dbafox\",\"isPartOf\":{\"@id\":\"https:\/\/dbafox.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/dbafox.com\/?p=509#primaryimage\"},\"image\":{\"@id\":\"https:\/\/dbafox.com\/?p=509#primaryimage\"},\"thumbnailUrl\":\"https:\/\/dbafox.com\/wp-content\/uploads\/provider_properties.png\",\"datePublished\":\"2015-10-06T07:30:45+00:00\",\"dateModified\":\"2018-09-18T05:59:11+00:00\",\"author\":{\"@id\":\"https:\/\/dbafox.com\/#\/schema\/person\/287adc474c1aebd398752ac4dcfe27eb\"},\"breadcrumb\":{\"@id\":\"https:\/\/dbafox.com\/?p=509#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/dbafox.com\/?p=509\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/dbafox.com\/?p=509#primaryimage\",\"url\":\"https:\/\/dbafox.com\/wp-content\/uploads\/provider_properties.png\",\"contentUrl\":\"https:\/\/dbafox.com\/wp-content\/uploads\/provider_properties.png\",\"width\":240,\"height\":200},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/dbafox.com\/?p=509#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/dbafox.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"OPENROWSET &#8211; Query Oracle from SQL Server using a linked server\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/dbafox.com\/#website\",\"url\":\"https:\/\/dbafox.com\/\",\"name\":\"dbafox\",\"description\":\"DBA Technical Information\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/dbafox.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/dbafox.com\/#\/schema\/person\/287adc474c1aebd398752ac4dcfe27eb\",\"name\":\"Ray Fox\",\"sameAs\":[\"http:\/\/www.dbafox.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"OPENROWSET - Query Oracle from SQL Server using a linked server - dbafox","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/dbafox.com\/?p=509","og_locale":"en_GB","og_type":"article","og_title":"OPENROWSET - Query Oracle from SQL Server using a linked server - dbafox","og_description":"Query Oracle from SQL Server using a linked server This post describes the basics of querying an Oracle database from Microsoft SQL Server. Oracle data can be queried from SQL Server via a linked server defined in Microsoft SQL Server &hellip; Continue reading &rarr;","og_url":"https:\/\/dbafox.com\/?p=509","og_site_name":"dbafox","article_published_time":"2015-10-06T07:30:45+00:00","article_modified_time":"2018-09-18T05:59:11+00:00","og_image":[{"url":"https:\/\/dbafox.com\/wp-content\/uploads\/provider_properties.png","type":"","width":"","height":""}],"author":"Ray Fox","twitter_misc":{"Written by":"Ray Fox","Estimated reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/dbafox.com\/?p=509","url":"https:\/\/dbafox.com\/?p=509","name":"OPENROWSET - Query Oracle from SQL Server using a linked server - dbafox","isPartOf":{"@id":"https:\/\/dbafox.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/dbafox.com\/?p=509#primaryimage"},"image":{"@id":"https:\/\/dbafox.com\/?p=509#primaryimage"},"thumbnailUrl":"https:\/\/dbafox.com\/wp-content\/uploads\/provider_properties.png","datePublished":"2015-10-06T07:30:45+00:00","dateModified":"2018-09-18T05:59:11+00:00","author":{"@id":"https:\/\/dbafox.com\/#\/schema\/person\/287adc474c1aebd398752ac4dcfe27eb"},"breadcrumb":{"@id":"https:\/\/dbafox.com\/?p=509#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/dbafox.com\/?p=509"]}]},{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/dbafox.com\/?p=509#primaryimage","url":"https:\/\/dbafox.com\/wp-content\/uploads\/provider_properties.png","contentUrl":"https:\/\/dbafox.com\/wp-content\/uploads\/provider_properties.png","width":240,"height":200},{"@type":"BreadcrumbList","@id":"https:\/\/dbafox.com\/?p=509#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/dbafox.com\/"},{"@type":"ListItem","position":2,"name":"OPENROWSET &#8211; Query Oracle from SQL Server using a linked server"}]},{"@type":"WebSite","@id":"https:\/\/dbafox.com\/#website","url":"https:\/\/dbafox.com\/","name":"dbafox","description":"DBA Technical Information","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/dbafox.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/dbafox.com\/#\/schema\/person\/287adc474c1aebd398752ac4dcfe27eb","name":"Ray Fox","sameAs":["http:\/\/www.dbafox.com"]}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3ecMb-8d","_links":{"self":[{"href":"https:\/\/dbafox.com\/index.php?rest_route=\/wp\/v2\/posts\/509","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dbafox.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dbafox.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dbafox.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dbafox.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=509"}],"version-history":[{"count":22,"href":"https:\/\/dbafox.com\/index.php?rest_route=\/wp\/v2\/posts\/509\/revisions"}],"predecessor-version":[{"id":1256,"href":"https:\/\/dbafox.com\/index.php?rest_route=\/wp\/v2\/posts\/509\/revisions\/1256"}],"wp:attachment":[{"href":"https:\/\/dbafox.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=509"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dbafox.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=509"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dbafox.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=509"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}