View Full Version : Connecting SQL Server 2005 without server side scripting????

11-24-2010, 08:06 AM

I am newbie in javascript. My client need an html page which directly query the sql server database and display the result(without using server side scripting). Since this is only used in intranet, he is not bothered much about security. I googled and found some code, but not working.

Here is the code I tested


<title>Entitled Document</title>
<script language="JavaScript" >

function getSubmit()
var LastName;
var Firstn = names.value ;
//var connection = new ActiveXObject("ADODB.Connection") ;
var cn = new ActiveXObject("ADODB.Connection");
var connectionstring="Data Source=<ipaddress>;Initial Catalog=<catalog>;User ID=<username>;Password=<password>;Provider=SQLOLEDB";
//here you must use forward slash to point strait
var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:/abc.mdb";
var rs = new ActiveXObject("ADODB.Recordset");
//var SQL = "INSERT INTO Customers(FirstName, Surname)"
//+ " VALUES ( '"+ names.value +"', '" + surname.value +"')";
var SQL = "select Surname, DOB from Customers where FirstName = '" + Firstn + "'";

rs.Open(SQL, cn);
surname.value = rs(0);
DOB.value = rs(1);



<input type="text" name="names" />
<input type="text" name="surname" />
<input type="text" name="DOB" />
<input type="button" value="submit" onclick="getSubmit()">



Is there any solution available???

Thanks in advance

11-24-2010, 11:11 AM
What browser are you testing that in? ActiveX controls will only work in IE.

NB. I may well be preaching to the converted, but it's worth saying anyway: putting your database manipulation code into client-side javascript is about as bad an idea as it's possible to have. Not only is it awful from a maintenance perspective to have your data model embedded in your presentation code, but you're reliant on JS for data validation - not that you're actually doing any in the code above. And obviously, any developer with half a wit about him who viewed the browser source code could own your intranet server inside a couple of minutes.

tl;dr: Please don't do this; it's a phenomenally bad idea.

11-24-2010, 11:29 AM
Dear Spudhead,

Thanks for your reply

It is true ,this one is a bad idea. But my client is reluctant to run any web server in the server side. Any solution without web server????

11-24-2010, 06:47 PM
I'm assuming you've already got a webserver sitting there since you're serving static html pages off it. And you've clearly got a database server - for all I know, they're on the same machine. The question is not how to create an intranet application without server-side technology. The question is why your client doesn't want to.

11-25-2010, 06:43 AM
The html pages are in local machine. The SQL Server database in on the Network. This is the reason why I mentioned there is no web server