{"id":66,"date":"2013-09-16T15:28:20","date_gmt":"2013-09-16T15:28:20","guid":{"rendered":"http:\/\/access-diva.com\/blog\/?p=66"},"modified":"2019-08-10T16:49:02","modified_gmt":"2019-08-10T20:49:02","slug":"persistent-connection-explained","status":"publish","type":"post","link":"https:\/\/access-diva.com\/blog\/?p=66","title":{"rendered":"Persistent Connection explained"},"content":{"rendered":"<p>You just went grocery shopping and your car is full of groceries. Which is faster?<\/p>\n<p>Take bag from car, open door to house, put bag inside house, go back out door closing and locking it behind you, repeat as many times till done<\/p>\n<p>OR<\/p>\n<p><strong>And, here&#8217;s the persistent connection part&#8230;<\/strong><br \/>\nTake bag from car, open door to house, put bag inside the house\u00a0and leave it open, repeat as many times till done<\/p>\n<p>Note how much faster the second part is, no reopening and unlocking the door to get in. It&#8217;s the same with a database, you are holding the *connection* open for *quicker* requests for information.<\/p>\n<blockquote><p><a href=\"http:\/\/www.accessmvp.com\/twickerath\/index.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Tom Wickerath Microsoft MVP (Access)<\/a> added&#8230; Without a persistent connection, lock the door after each trip, and reset the security alarm system. Then, when returning with the second bag of groceries, disable the security system and unlock the door. Repeat this laborious sequence until you have all your groceries brought in.<\/p><\/blockquote>\n<p><strong>Technically\u00a0explained<\/strong> <strong>by<\/strong> <a href=\"http:\/\/www.accessmvp.com\/twickerath\/index.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Tom Wickerath Microsoft MVP (Access)<\/a>&#8230;<\/p>\n<blockquote><p>A persistent connection is *very helpful* in speeding up shared Access applications, including relinking tables. You can run a simple experiment, timing how long it takes to relink tables with and without a persistent connection, and you should see a vast improvement with a persistent connection present. Persistent connections prevent the file server from continually deleting and re-creating a locking database file, when there is a single user using the application. \u00a0The FE clients can re-use a connection that has been persisted, instead of having to spend the time creating a new connection each time.\u00a0 Regardless of your specific issue, I highly recommend that you implement persistent connections to all BE JET databases, for your Access applications.<\/p><\/blockquote>\n<p>So how do you maintain a persistent connection?\u00a0 In your Utilities Module add&#8230;<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">Public rsAlwaysOpen As Recordset<\/pre>\n<p>If you don&#8217;t have a Table that is open ALL the time create one.\u00a0 It doesn&#8217;t need any records it just needs to be a Tables linked in the Front end.\u00a0 Then on a your Main Form or a hidden Form in the On_Open event procedures add&#8230;<\/p>\n<p><code>Set rsAlwaysOpen = CurrentDb.OpenRecordset(\"YourTableNameHere\")<\/code><\/p>\n<p>Now, you want to make sure you close that connection when exiting your database.\u00a0 So, on the On_Close event of the Main Form add&#8230;<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">rsAlwaysOpen.Close\r\nSet rsAlwaysOpen = Nothing<\/pre>\n<p>Now you will have a persistent connection which will improves your use of the database not having to reopen it every time you open a Form.<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_66\" class=\"pvc_stats all  \" data-element-id=\"66\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/access-diva.com\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>You just went grocery shopping and your car is full of groceries. Which is faster?<\/p>\n<p>Take bag from car, open door to house, put bag inside house, go back out door closing and locking it behind you, repeat as many times till done<\/p>\n<p>OR<\/p>\n<p>And, here&#8217;s the persistent connection part&#8230; Take bag from car, open [&#8230;]<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_66\" class=\"pvc_stats all  \" data-element-id=\"66\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/access-diva.com\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49],"tags":[53],"class_list":["post-66","post","type-post","status-publish","format-standard","hentry","category-database-design","tag-persistent-connection","odd"],"_links":{"self":[{"href":"https:\/\/access-diva.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/66","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/access-diva.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/access-diva.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/access-diva.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/access-diva.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=66"}],"version-history":[{"count":9,"href":"https:\/\/access-diva.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/66\/revisions"}],"predecessor-version":[{"id":486,"href":"https:\/\/access-diva.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/66\/revisions\/486"}],"wp:attachment":[{"href":"https:\/\/access-diva.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=66"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/access-diva.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=66"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/access-diva.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=66"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}