This topic is locked
[SOLVED]

 checking DB connectivity... works!

6/29/2020 2:34:20 PM
ASPRunner.NET General questions
H
heilmanmd author

Below is code that works for checking DB connectivity to ensure to trap nasty error msg so user doesn't see it if db can't be connected to
this uses a XSession.Session["nosqlsrvr"] variable ( doing this in ASP.NET )
which gets passed along so that if yes then put up a jquery dialogue telling user, sorry, no db connection, etc... etc...
If want more detail let me know and can provide
Best

Mark
--------------------------------------
sqlcmd = "select count(*) as hits from (select sampleid,method from dbo.nye_result where processed = 0 group by sampleid,method ) a ;" ;
// switch over to Sql Server

DB.SetConnection("ODBC:lims_test");
try{
// gotta put all the variable declarations withing the try for db stuff

// if not, won't work !!!! go figure...

dynamic rs2 = DB.Query(sqlcmd);

dynamic record;

// -------------------------------------------
record = rs2.fetchAssoc();
if(record ) {

hits = record["hits"];

XSession.Session["numassays"]=hits ;

}

}

// gotta catch something, if not won't work... gasp... but examples all show can do it without catching anything...

catch(Exception e) {
nosqlsrvr="yes" ;

XSession.Session["nosqlsrvr"] = nosqlsrvr;

nosqlsrvr_count = XSession.Session["nosqlsrvr_count"] ;

XSession.Session["nosqlsrvr_count"] = nosqlsrvr_count ;

}
// switch back to primary connection aka DB2 ...

DB.SetConnection("");
---------------------
//pass along to java on load event in follow on page
nosqlsrvr = XSession.Session["nosqlsrvr"];

pageObject.setProxyValue("nosqlsrvr",nosqlsrvr);
------------------

// js on load event of the follow on page
var nosqlsrvr_count = proxy["nosqlsrvr_count"];
// alert("nosqlsrvr=" + nosqlsrvr + " nosqlsrvrcount=" + nosqlsrvr_count);
if ( nosqlsrvr === 'yes') {

if( nosqlsrvr_count <= 1 ){

$("#nolims").dialog({

position: { my: 'top', at: 'top+200' },

resizable: false,

closeOnEscape: false,

autoOpen: true,

height: 390,

maxHeight: 520,

width: 450,

maxWidth:620,

title: "No LIMS Alert",

modal: true,

open: function () {

markup = '
<Br><font color = "red">WARNING !!!! WARNING !!!!

</font></b>Unable to send or receive Samples & Assays.

' +

'Please contact the IS Department. Thank you....';

$(this).html(markup);

$(".ui-dialog-titlebar-close").hide();

$(this).parents('.ui-dialog-buttonpane button:eq(0)').focus();

},

buttons: [

{

text: "CONTINUE",

click: function() {

$(this).dialog("close");

}

}

]

});

}

}