Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    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.

  • Users who have thanked Spudhead for this post:

    kuttan939 (11-24-2010)

  • #3
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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????

  • #4
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    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.

  • #5
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •