Can we connect to a database(Oracle,SQL Server) using javascript. If yes please provide me with an example.
Thanks in advace
Can we connect to a database(Oracle,SQL Server) using javascript. If yes please provide me with an example.
Thanks in advace
Actually, yes you can! Not to contradict all comments saying you can't but it depends on which rights you allow the client through ActiveX and ADODB.
Example:
function dblookup()
{
var myConnect = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=d:\\sdi.mdb";
var ConnectObj = Server.CreateObject("ADODB.Connection");
var RS = Server.CreateObject("ADODB.Recordset");
var sql="SELECT * FROM employeespulled WHERE empid='1';";
ConnectObj.Open (myConnect);
RS.Open(sql,ConnectObj,adOpenForwardOnly,adLockReadOnly,adCmdText);
var fieldCount = RS.Fields.Count;
Response.Write ("Field Count" + fieldCount);
RS.Close();
ConnectObj.Close();
}
As this is an "old" way of doing things, I only recommend this in a private environment (intranet) as the security risk is pretty big.
In the modern era you would configure a webservice on the server which takes a few parameters and sends a callback function to the client. That way you take the security risk to the server and not to the client.