Showing posts with label coldfusion. Show all posts
Showing posts with label coldfusion. Show all posts

Wednesday, January 3, 2018

ColdFusion not maintaining connection to Azure Data Warehouse

Leave a Comment

Our ColdFusion 2016 Enterprise server (Windows Server 2012 R2) is not maintaining connections to an Azure Data Warehouse. The first Azure query on a page takes a second or more to run. Subsequent Azure queries on the same page take a fraction of a second, e.g.:

test1 (Datasource=azureDev, **Time=3485ms**, Records=1) in D:\DW\dwtest\CF2016\bob\azureAdhoc.cfm @ 12:10:12.012 select count(*) cnt from dimpatient where name like 'smith%' and birthdate >'2014-02-01'   test2 (Datasource=AzureDev, **Time=125ms**, Records=3) in D:\DW\dwtest\CF2016\bob\azureAdhoc.cfm @ 12:10:12.012 select * from dbo.dimPatientMergeStatus   test3 (Datasource=azureDev, **Time=281ms**, Records=1) in D:\DW\dwtest\CF2016\bob\azureAdhoc.cfm @ 12:10:13.013 select count(*) cnt from dimpatient where name like 'jones%' and birthdate >'2004-02-01'  

It seems apparent that CF is taking extra time to actually make the connection while running the first query on the page. We've tried with various queries and re-arranging their order and always end up with the same result.

We are connecting to Azure using the latest MS jdbc driver (mssql-jdbc-6.2.2.jre8.jar) and 'Maintain Connections' is checked. We first attempted to connect using the built in Microsoft SQL Server driver but kept getting this error:

Connection verification failed for data source: AzureDev2 java.sql.SQLException: [Macromedia][SQLServer JDBC Driver]Error fetching requested database meta-data info. 

We do not see this issue when we run the queries in SSMS.

Any idea what might be wrong?

1 Answers

Answers 1

How does ColdFusion Server manage database connections when there are client variables?

With ColdFusion Server version 4.5.1 SP1 and higher, when you store your client variables in a database, your code connects to the database only when a variable is set. This prevents unnecessary database connections, for instance, in a case where you are using client management, but no client variables are present in a particular request.

https://helpx.adobe.com/coldfusion/kb/database-connections-handled-coldfusion.html

Read More

Saturday, April 9, 2016

Sortable with jQuery and Ajax

Leave a Comment

I have data that I am accessing via ajax from a Coldfusion component. I am trying to display the data in a sortable jQuery ui format but the sortable feature is not working. Here is the code I am trying to use.

$(document).ready(function() {      // get assets to display     var showid = <cfoutput>'#SESSION.Show#'</cfoutput>;     var html = "";      function assetsPost() {         $.ajax({             cache: false,             type:'POST',             url:'cfc/cfc_COLF.cfc?method=qCOLF&returnformat=json',             dataType: "json",             data: {               show_id:    showid             },             success:function(data) {                 if(data && data.length) {   // DO SOMETHING                            html += "<ul id='sortable'>";                  jQuery.each(data, function(i, val) {                          var linkID         = data[i].linkID;                      var description    = data[i].description;                      var discussion     = data[i].discussion;                      var linkurl        = data[i].linkurl;                      var index          = i;                          html += "<li id=' " + index + " ' class='ui-state-default'>";                                            html += "<h5 style='color:#000; text-align:left;'>";                          html += "<a class='process-asset' id=' " + linkID + " ' name='done'><img src='images/icon_done.png'></a>";                          html += "<a href='" + linkurl + "' target='_blank'> " + description + "</a>";                          html += "<a class='process-asset' id=' " + linkID + " ' name='remove' style='color:#000; float:right;'><img src='images/icon_remove.png'></a>";                          html += "</h5>";                          html += "<p style='color:#000; margin:5px 15px 5px 15px; text-align:left;'> " + discussion + "</p>";                          html += "</li>";                 });                          html += "</ul>";                   $('#linkoutput').html( html );                  //alert(html);                 } else { // DO SOMETHING                  }             }         });     }       assetsPost();  });  $(document).ready(function() {          //sort order        $(function() {         $("#sortable").sortable({             opacity: 0.6,             update: function(event, ui) {              var Order = $("#sortable").sortable('toArray').toString();           $('#order').val(Order);             //alert(Order);             }         });             $( "#sortable" ).disableSelection();     });     // set up sort order for form submission     $("#mForm").submit(function() {         $("#order").val($("#sortable").sortable('toArray'))   });   }); 

All the data and the jQuery is loading just fine. In fact, if I added the following code and this list sorts just fine.

<ul id="sortable">   <li id="1" class="ui-state-default ">       <h5>1</h5>   </li>   <li id="2" class="ui-state-default ">       <h5>2</h5>   </li>   <li id="3" class="ui-state-default ">       <h5>3</h5>   </li> </ul> 

So there has to be some sort of conflict in the ajax section of code. Any advice is appreciated.

2 Answers

Answers 1

You are making the list sortable, which changes the list and its elements, and then later replacing that list once your callback returns. You need to move your $("#sortable").sortable({ ... code into your success callback, after you've inserted the new list.

Answers 2

Some of your example code seems to be missing or incorrect. I have reviewed it and created the following example: https://jsfiddle.net/Twisty/hfdg5y20/

HTML

<div class='sort-wrap'>   <ul id="sortable">     <li id="1" class="ui-state-default ">       <h5>1</h5>     </li>     <li id="2" class="ui-state-default ">       <h5>2</h5>     </li>     <li id="3" class="ui-state-default ">       <h5>3</h5>     </li>   </ul> </div> <label>Order:</label> <input type="text" id="order" /> 

JQUERY

$(document).ready(function() {   // get assets to display   //var showid = < cfoutput > '#SESSION.Show#' < /cfoutput>;   var showid = 10000000001;   var html = "";    function assetsPost() {     $.ajax({       cache: false,       type: 'POST',       url: '/echo/json/',       dataType: "json",       data: {         show_id: showid,         json: JSON.stringify([{           'linkID': 4,           'description': "stuff",           'discussion': "thread",           'linkurl': "http://www.example.com/"         }])       },       success: function(data) {         console.log(data);         if (data && data.length) { // DO SOMETHING             //html += "<ul id='sortable'>";           var html = "";            jQuery.each(data, function(i, val) {             var linkID = data[i].linkID;             var description = data[i].description;             var discussion = data[i].discussion;             var linkurl = data[i].linkurl;             var index = $("#sortable li").length + 1;             html += "<li id='" + index + "' class='ui-state-default'>";             html += "<h5 style='color:#000; text-align:left;'>";             html += "<a class='process-asset' id=' " + linkID + " ' name='done'><img src='images/icon_done.png'></a>";             html += "<a href='" + linkurl + "' target='_blank'> " + description + "</a>";             html += "<a class='process-asset' id=' " + linkID + " ' name='remove' style='color:#000; float:right;'><img src='images/icon_remove.png'></a>";             html += "</h5>";             html += "<p style='color:#000; margin:5px 15px 5px 15px; text-align:left;'> " + discussion + "</p>";             html += "</li>";           });           //html += "</ul>";           console.log(html);            $('#sortable').append(html);           $("#order").val($("#sortable").sortable('toArray'));           //alert(html);         } else { // DO SOMETHING          }       }     });   }   assetsPost();    $("#sortable").sortable({     opacity: 0.6,     update: function(event, ui) {       var Order = $("#sortable").sortable('toArray').toString();       $('#order').val(Order);       //alert(Order);     }   });   $("#sortable").disableSelection();   // set up sort order for form submission   $("#mForm").submit(function() {     $("#order").val($("#sortable").sortable('toArray'));   }); }); 

This is using the jsfiddle method to mimic AJAX to show the working code. Yours will be a bit different and may have different results depending on the data that is returned.

The new item is appended to the end of the list. I did not find $('#linkoutput') in your HTML, so I appended to $('#sortable'). You can grab and sort the new item in the list just like the others. Understand that sortable will not arrange the items for you but allow the user to reorder them at will. See more: https://jqueryui.com/sortable/

Read More