Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-24-2010, 07:06 AM   PM User | #1
kuttan939
New to the CF scene

 
Join Date: Nov 2010
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
kuttan939 is an unknown quantity at this point
Question Connecting SQL Server 2005 without server side scripting????

Hi,

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

[CODE]

<html>
<head>
<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 + "'";

cn.Open(strConn);
rs.Open(SQL, cn);
surname.value = rs(0);
DOB.value = rs(1);
//alert(rs(0));
rs.Close();
cn.Close();


}

</script>
</head>
<body>

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

</body>
</html>

[CODE]

Is there any solution available???

Thanks in advance
kuttan939 is offline   Reply With Quote
Old 11-24-2010, 10:11 AM   PM User | #2
Spudhead
Senior Coder

 
Spudhead's Avatar
 
Join Date: Jun 2002
Location: London, UK
Posts: 1,856
Thanks: 8
Thanked 110 Times in 109 Posts
Spudhead is on a distinguished road
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.
Spudhead is offline   Reply With Quote
Users who have thanked Spudhead for this post:
kuttan939 (11-24-2010)
Old 11-24-2010, 10:29 AM   PM User | #3
kuttan939
New to the CF scene

 
Join Date: Nov 2010
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
kuttan939 is an unknown quantity at this point
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????
kuttan939 is offline   Reply With Quote
Old 11-24-2010, 05:47 PM   PM User | #4
Spudhead
Senior Coder

 
Spudhead's Avatar
 
Join Date: Jun 2002
Location: London, UK
Posts: 1,856
Thanks: 8
Thanked 110 Times in 109 Posts
Spudhead is on a distinguished road
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.
Spudhead is offline   Reply With Quote
Old 11-25-2010, 05:43 AM   PM User | #5
kuttan939
New to the CF scene

 
Join Date: Nov 2010
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
kuttan939 is an unknown quantity at this point
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

Thanks
kuttan939 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:52 AM.


Advertisement
Log in to turn off these ads.