Execute Stored Procedures From Screens

We discovered a way to execute SQL Stored procedures from HRNET screens, via JavaScript custom script. Nothing new for the world of JS, but new for us. I did not know you can run sql queries from JavaScript…
Here is the example:

function executeStoredProcedue(){
   var connection = new ActiveXObject("ADODB.Connection"); 
   var recSet = new ActiveXObject("ADODB.Recordset"); 
   var cmd = new ActiveXObject("ADODB.Command");
   var ConnectionString = "Data Source=SQLSERVER;Provider=SQLOLEDB;User Id=user;Password=password;Persist Security Info=True;Initial Catalogue=HRNET_DATABASE;" ;

   var record_ID =  document.getElementById("hdRecordID").value;

   cmd.ActiveConnection = ConnectionString ;
   cmd.CommandText = "HRNETDatabase.DBO.name_of_stored_procedure" ;
   cmd.CommandType = 4 ;
   recset = cmd.Execute(null,[record_ID]);

The only drawback is that every time you have this running in IE, you will get a security warning from ActiveX. Also this will not work in Firefox, if your clients will happen to use it.

This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published.