How to connect database using only javascript

Discussion in 'JavaScript' started by optionsbinary, Jan 14, 2012.

  1. #1
    I have a doubt
    I want to connect database in my ASP.net application using java script to run faster.
    As in serverside its bit slow as anytime the postback method is calling
    so I think client side will be faster
    So is it possible ?
     
    optionsbinary, Jan 14, 2012 IP
  2. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #2
    Like you said JavaScript is client side and the db is on the server. So how do you think it connects? Javascript can't do it. You will always need a server side scripting language to do this.
     
    stephan2307, Jan 16, 2012 IP
  3. Sgarena

    Sgarena Greenhorn

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    These is simple, YOU CAN'T.
    Javascript is clientside you can't connect it to a database on the serverside.
     
    Sgarena, Jan 17, 2012 IP
  4. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #4


    no you can't. javascript is client-side scripting, database is server-side.. however you can communicate with it through AJAX..
     
    JohnnySchultz, Jan 17, 2012 IP
  5. demonbyte

    demonbyte Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Although javascript is client-side you can retrieve the data through AJAX after the initial page load. This would be beneficial if you are seeing a slow initial load-time when going to the page initially. Have the javascript call an ajax function on load that retrieves the data necessary to populate the page.
     
    demonbyte, Jan 18, 2012 IP
  6. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #6
    Yes that's right but that is not what the original question was. AJAX still requires a server side script and does not connect directly to the database
     
    stephan2307, Jan 18, 2012 IP
  7. demonbyte

    demonbyte Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I was merely giving suggestions on how to make his application potentially faster. Other people had already answered his original question. Was this wrong of me?
     
    demonbyte, Jan 18, 2012 IP
  8. FizixRichard

    FizixRichard Peon

    Messages:
    26
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    demonbyte, there is a big flaw with what you've suggested that will cause big problems for the guys client. Even if you rely on AJAX, turn javascript off and the site is dead, also you don't want a standalone connect script for your DB connection exposing.

    If your dynamically retrieving say comment updates, the method you suggest is fine as its a trivial bit of content (i.e. load 10 comments natively then update the list periodically with JavaScript/AJAX). As if JS is turned off, the list simply wont auto update, so it degrades well (provided you have native navigation).

    Not picking at you, but I'd say it was a bit of bad advice, when I think the answer is no you can't without AJAX and you shouldn't depend on that either.

    Also, worth considering, if you do it by AJAX and do go with it, and have say 10 items on the page, each calling your DB you are potentially making 10 separate connections to the DB Server, when inside say PHP or ASP.NET you can do it with one connection and flow it through nicely. So potentially the AJAX method would be slower under load.
     
    FizixRichard, Jan 23, 2012 IP