{"id":12082,"date":"2011-11-11T18:20:22","date_gmt":"2011-11-11T18:20:22","guid":{"rendered":"http:\/\/www.learnexcelmacro.com\/?p=417"},"modified":"2022-08-06T12:12:14","modified_gmt":"2022-08-06T12:12:14","slug":"oracle-connection-string-in-vba","status":"publish","type":"post","link":"https:\/\/vmlogger.com\/excel\/2011\/11\/oracle-connection-string-in-vba\/","title":{"rendered":"Oracle Connection String in VBA"},"content":{"rendered":"<p>Dear Friends,<\/p>\n<p>Using Excel Macros (VBA) you can connect to Databases like SQL, Oracle or Access DB. In this Article, I will teach you, how you can do a connection with a Oracle Server.<br \/>\nWe can do connection with Oracle either by giving <strong>SID <\/strong>(Oracle <strong>S<\/strong>ystem <strong>ID<\/strong>) or <strong>Service Name<\/strong>. Whichever is available for the connection, we can use them to connect to the Oracle Database.<\/p>\n<h2>Prerequisite<\/h2>\n<p>Before running the below code, you need to Add reference for ADODB Connection. If you do not know how to add references for ADODB connection in Excel workbook, follow below steps.<\/p>\n<h2>Step to Add ADODB Connection References in Excel <\/h2>\n<div class=\"alert alert-warning\">\n<strong>1.<\/strong> Go to VB Editor Screen (Alt+F11)<br \/>\n<strong>2.<\/strong> Tools \u2013> References\u2026<br \/>\n<strong>3.<\/strong> From the List of Available References Select \u201c<strong>Microsoft ActiveX Data Objects 2.0 Library<\/strong>\u201d You can select 2.0 Version or any other higher version of this reference.<br \/>\n<strong>4.<\/strong> Click OK\n<\/div>\n<p><a href=\"#Connection-with-SID\">\u00a0 Connection String with SID\u00a0<\/a><br \/>\n<a href=\"#Connection-with-Service\">Connection String with Service(DB Name)\u00a0<\/a><\/p>\n<p><a name=\"Connection-with-SID\"><\/a><\/p>\n<h2><strong>Oracle Connection String with SID:<\/strong><\/h2>\n<p>Use the below Code for connecting to the Oracle Database.<\/p>\n<p><a name=\"Connection-with-SID\"><\/a><\/p>\n<pre>\r\n<code class=\"language-vbnet\">\r\nSub Ora_Connection()\r\nDim con As ADODB.Connection\r\nDim rs As ADODB.Recordset\r\nDim query As String\r\nSet con = New ADODB.Connection\r\nSet rs = New ADODB.Recordset\r\n'---- Replace below highlighted names with the corresponding values\r\nstrCon = \"Driver={Microsoft ODBC for Oracle}; \" &amp; _\r\n\"CONNECTSTRING=(DESCRIPTION=\" &amp; _\r\n\"(ADDRESS=(PROTOCOL=TCP)\" &amp; _\r\n\"(HOST=Your Host Name)(PORT=Port Number))\" &amp; _\r\n\"(CONNECT_DATA=(SID=SID of your Database))); uid=User ID; pwd=Password;\"\r\n'---  Open \u00a0\u00a0the above connection string.\r\ncon.Open (strCon)\r\n'---  Now connection is open and you can use queries to execute them. \r\n'---  It will be open till you close the connection\r\nEnd Sub\r\n<\/code>\r\n<\/code><\/pre>\n<p><a name=\"Connection-with-Service\"><\/a><\/p>\n<h2><strong>Oracle Connection String with Service:<\/strong><\/h2>\n<p>Use the below Code for connecting to the Oracle Database.<\/p>\n<p><a name=\"Connection-with-Service\"><\/a><\/p>\n<pre>\r\n<code class=\"language-vbnet\">\r\n\r\nSub Ora_Connection()\r\nDim con As ADODB.Connection\r\nDim rs As ADODB.Recordset\r\nDim query As String\r\nSet con = New ADODB.Connection\r\nSet rs = New ADODB.Recordset\r\n'---  Replace below highlighted names with the corresponding values\r\nstrCon = \"Driver={Microsoft ODBC for Oracle}; \" &amp; _\r\n\"CONNECTSTRING=(DESCRIPTION=\" &amp; _\r\n\"(ADDRESS=(PROTOCOL=TCP)\" &amp; _\r\n\"(HOST=Your Host Name)(PORT=Enter Port Number))\" &amp; _\r\n\"(CONNECT_DATA=(SERVICE_NAME=database))); uid=Enter User ID; pwd=Enter Password;\"\r\n'---  Open the above connection string.\r\ncon.Open (strCon)\r\n'---  Now connection is open and you can use queries to execute them.\r\n'---  It will be open till you close the connection\r\nEnd Sub\r\n<\/code>\r\n<\/code><\/pre>\n<h2>Read this Also:<\/h2>\n<ul>\n<li>\n<a href=\"https:\/\/vmlogger.com\/excel\/2011\/11\/sql-connection-string\/\" target=\"_blank\" rel=\"noopener\">How to Connect to SQL Database using Excel Macros<\/a>\n<\/li>\n<li>\n<a href=\"https:\/\/vmlogger.com\/excel\/2011\/11\/oracle-connection-string-in-vba\/\"target=\"_blank\">How to Connect to Oracle Database using Excel Macros<\/a>\n<\/li>\n<li>\n<a href=\"https:\/\/vmlogger.com\/excel\/2011\/12\/how-to-connect-to-access-database-excel-macro\/\"target=\"_blank\">How to Connect to Access Database using Excel Macros<\/a>\n<\/li>\n<\/ul>\n<span class=\"et_bloom_bottom_trigger\"><\/span>","protected":false},"excerpt":{"rendered":"<p>Dear Friends, Using Excel Macros (VBA) you can connect to Databases like SQL, Oracle or Access DB. In this Article, I will teach you, how you can do a connection with a Oracle Server. We can do connection with Oracle either by giving SID (Oracle System ID) or Service Name. Whichever is available for the [&hellip;]<\/p>\n","protected":false},"author":45,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","rop_custom_images_group":[],"rop_custom_messages_group":[],"rop_publish_now":"initial","rop_publish_now_accounts":{"facebook_10221221723514640_204908552914904":"","twitter_aTo1MTIwNTUyMDQ7_512055204":""},"rop_publish_now_history":[],"rop_publish_now_status":"pending","footnotes":""},"categories":[5203,1246,1675],"tags":[],"class_list":["post-12082","post","type-post","status-publish","format-standard","hentry","category-database","category-macro","category-excel-macro-for-beginners"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v23.5 (Yoast SEO v23.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Oracle Connection String in VBA - Let&#039;s excel in Excel<\/title>\n<meta name=\"description\" content=\"Oracle Connection string in VBA. VBA to connect to Oracle DB. Excel macro to connect to Oracle DB with SID. VBA to connect Oracle using Service Name.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/vmlogger.com\/excel\/2011\/11\/oracle-connection-string-in-vba\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Oracle Connection String in VBA\" \/>\n<meta property=\"og:description\" content=\"Oracle Connection string in VBA. VBA to connect to Oracle DB. Excel macro to connect to Oracle DB with SID. VBA to connect Oracle using Service Name.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/vmlogger.com\/excel\/2011\/11\/oracle-connection-string-in-vba\/\" \/>\n<meta property=\"og:site_name\" content=\"Let&#039;s excel in Excel\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/www.facebook.com\/vmlogger\" \/>\n<meta property=\"article:author\" content=\"http:\/\/www.facebook.com\/vmlogger\" \/>\n<meta property=\"article:published_time\" content=\"2011-11-11T18:20:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-06T12:12:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/vmlogger.com_-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Vishwamitra Mishra\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/www.twitter.com\/learnexcelmacro\" \/>\n<meta name=\"twitter:site\" content=\"@learnexcelmacro\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Vishwamitra Mishra\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. 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\":\"Article\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2011\/11\/oracle-connection-string-in-vba\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2011\/11\/oracle-connection-string-in-vba\/\"},\"author\":{\"name\":\"Vishwamitra Mishra\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"headline\":\"Oracle Connection String in VBA\",\"datePublished\":\"2011-11-11T18:20:22+00:00\",\"dateModified\":\"2022-08-06T12:12:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2011\/11\/oracle-connection-string-in-vba\/\"},\"wordCount\":216,\"commentCount\":56,\"publisher\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"articleSection\":[\"Database\",\"Excel Macro\",\"Excel Macro Tutorial\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/vmlogger.com\/excel\/2011\/11\/oracle-connection-string-in-vba\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2011\/11\/oracle-connection-string-in-vba\/\",\"url\":\"https:\/\/vmlogger.com\/excel\/2011\/11\/oracle-connection-string-in-vba\/\",\"name\":\"Oracle Connection String in VBA - Let&#039;s excel in Excel\",\"isPartOf\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#website\"},\"datePublished\":\"2011-11-11T18:20:22+00:00\",\"dateModified\":\"2022-08-06T12:12:14+00:00\",\"description\":\"Oracle Connection string in VBA. VBA to connect to Oracle DB. Excel macro to connect to Oracle DB with SID. VBA to connect Oracle using Service Name.\",\"breadcrumb\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2011\/11\/oracle-connection-string-in-vba\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/vmlogger.com\/excel\/2011\/11\/oracle-connection-string-in-vba\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2011\/11\/oracle-connection-string-in-vba\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/vmlogger.com\/excel\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Database\",\"item\":\"https:\/\/vmlogger.com\/excel\/database\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Oracle Connection String in VBA\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#website\",\"url\":\"https:\/\/vmlogger.com\/excel\/\",\"name\":\"Let&#039;s excel in Excel\",\"description\":\"Let&#039;s share knowledge\",\"publisher\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/vmlogger.com\/excel\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\",\"name\":\"Vishwamitra Mishra\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png\",\"contentUrl\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png\",\"width\":528,\"height\":560,\"caption\":\"Vishwamitra Mishra\"},\"logo\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/\"},\"description\":\"My name is Vishwamitra Mishra. Friends Call me Vishwa. I hold a Bachelor\u2019s Degree in Computer Science from D.A.V.V. Indore &amp; currently working as a Technical Lead having over 7 years of experience.\",\"sameAs\":[\"http:\/\/www.learnexcelmacro.com\",\"http:\/\/www.facebook.com\/vmlogger\",\"https:\/\/x.com\/https:\/\/www.twitter.com\/learnexcelmacro\",\"https:\/\/www.youtube.com\/c\/VMLogger\"],\"url\":\"https:\/\/vmlogger.com\/excel\/author\/vishwamitra\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Oracle Connection String in VBA - Let&#039;s excel in Excel","description":"Oracle Connection string in VBA. VBA to connect to Oracle DB. Excel macro to connect to Oracle DB with SID. VBA to connect Oracle using Service Name.","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:\/\/vmlogger.com\/excel\/2011\/11\/oracle-connection-string-in-vba\/","og_locale":"en_US","og_type":"article","og_title":"Oracle Connection String in VBA","og_description":"Oracle Connection string in VBA. VBA to connect to Oracle DB. Excel macro to connect to Oracle DB with SID. VBA to connect Oracle using Service Name.","og_url":"https:\/\/vmlogger.com\/excel\/2011\/11\/oracle-connection-string-in-vba\/","og_site_name":"Let&#039;s excel in Excel","article_publisher":"http:\/\/www.facebook.com\/vmlogger","article_author":"http:\/\/www.facebook.com\/vmlogger","article_published_time":"2011-11-11T18:20:22+00:00","article_modified_time":"2022-08-06T12:12:14+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/vmlogger.com_-1.png","type":"image\/png"}],"author":"Vishwamitra Mishra","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/www.twitter.com\/learnexcelmacro","twitter_site":"@learnexcelmacro","twitter_misc":{"Written by":"Vishwamitra Mishra","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/vmlogger.com\/excel\/2011\/11\/oracle-connection-string-in-vba\/#article","isPartOf":{"@id":"https:\/\/vmlogger.com\/excel\/2011\/11\/oracle-connection-string-in-vba\/"},"author":{"name":"Vishwamitra Mishra","@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"headline":"Oracle Connection String in VBA","datePublished":"2011-11-11T18:20:22+00:00","dateModified":"2022-08-06T12:12:14+00:00","mainEntityOfPage":{"@id":"https:\/\/vmlogger.com\/excel\/2011\/11\/oracle-connection-string-in-vba\/"},"wordCount":216,"commentCount":56,"publisher":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"articleSection":["Database","Excel Macro","Excel Macro Tutorial"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/vmlogger.com\/excel\/2011\/11\/oracle-connection-string-in-vba\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/vmlogger.com\/excel\/2011\/11\/oracle-connection-string-in-vba\/","url":"https:\/\/vmlogger.com\/excel\/2011\/11\/oracle-connection-string-in-vba\/","name":"Oracle Connection String in VBA - Let&#039;s excel in Excel","isPartOf":{"@id":"https:\/\/vmlogger.com\/excel\/#website"},"datePublished":"2011-11-11T18:20:22+00:00","dateModified":"2022-08-06T12:12:14+00:00","description":"Oracle Connection string in VBA. VBA to connect to Oracle DB. Excel macro to connect to Oracle DB with SID. VBA to connect Oracle using Service Name.","breadcrumb":{"@id":"https:\/\/vmlogger.com\/excel\/2011\/11\/oracle-connection-string-in-vba\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/vmlogger.com\/excel\/2011\/11\/oracle-connection-string-in-vba\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/vmlogger.com\/excel\/2011\/11\/oracle-connection-string-in-vba\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/vmlogger.com\/excel\/"},{"@type":"ListItem","position":2,"name":"Database","item":"https:\/\/vmlogger.com\/excel\/database\/"},{"@type":"ListItem","position":3,"name":"Oracle Connection String in VBA"}]},{"@type":"WebSite","@id":"https:\/\/vmlogger.com\/excel\/#website","url":"https:\/\/vmlogger.com\/excel\/","name":"Let&#039;s excel in Excel","description":"Let&#039;s share knowledge","publisher":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/vmlogger.com\/excel\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5","name":"Vishwamitra Mishra","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/","url":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png","contentUrl":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png","width":528,"height":560,"caption":"Vishwamitra Mishra"},"logo":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/"},"description":"My name is Vishwamitra Mishra. Friends Call me Vishwa. I hold a Bachelor\u2019s Degree in Computer Science from D.A.V.V. Indore &amp; currently working as a Technical Lead having over 7 years of experience.","sameAs":["http:\/\/www.learnexcelmacro.com","http:\/\/www.facebook.com\/vmlogger","https:\/\/x.com\/https:\/\/www.twitter.com\/learnexcelmacro","https:\/\/www.youtube.com\/c\/VMLogger"],"url":"https:\/\/vmlogger.com\/excel\/author\/vishwamitra\/"}]}},"_links":{"self":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts\/12082"}],"collection":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/users\/45"}],"replies":[{"embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/comments?post=12082"}],"version-history":[{"count":0,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts\/12082\/revisions"}],"wp:attachment":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/media?parent=12082"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/categories?post=12082"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/tags?post=12082"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}