Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Connecting to Database using Javascript both in IE and FireFox

  1. #1
    Join Date
    Dec 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Connecting to Database using Javascript both in IE and FireFox

    HI Everyone,
    I am trying to connect to the client database from the application deployed in server. I have done this using ActiveXObjects. It is working fine in IE but problem with FireFox. Since FF don't allow ActiveXObjects i decided to do this without using ActiveXObjects.
    It is very urgent can anyone help me in this.


    Thanks in advance...

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    ActiveX is weird. It's IE only, and has special stuff it can do (and presents security risks, etc. to the user).

    Aside from ActiveX, which, as I said, is a weird exception, javascript cannot connect to a database. Rather, you must use PHP or another server side language to do so.

    The only other similar option is Java (not javascript, but a Java applet) since it can do many things similar to ActiveX and is friendly to many browsers, though the user, for each, will need the Java plugin, and, since is presents security holes and risks, the user must allow it to have access.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Dec 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Sample code for connecting to Database using Javascript both in IE and FireFox

    HI,

    Thanks for giving advice.
    Could you pls help me by providing the sample code to implement the solution.

  4. #4
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,626
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Activex works without much problems on the server-side.

    In ASP, ASP.NET they employ Activex.

    Why don't you post the code you were using or the language preference for this job.

  5. #5
    Join Date
    Dec 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Sample code for connecting to Database using Javascript only in IE

    HI,

    Code below is what i am using. This is working fine with IE, but problem with FF. Since FF doesn't support ActiveXObjects.

    I need a sample code to connect client database from the server application(testDB.asp) which is compatible with IE and FF

    pls help me it is very urgent.

    filename: testDB.asp
    <html>
    <head>
    <script type="text/javascript">
    var conn = new ActiveXObject("ADODB.Connection")
    var conn_str = ""
    var dbHost = ""
    var dbUser = ""
    var dbPassword = ""
    var dbProvider = ""
    var dbDefault = ""
    function getData()
    {
    dbHost = "localhost";
    dbUser = "sa";
    dbPassword = "";
    dbProvider = "SQLOLEDB";
    dbDefault = "Northwind";
    conn_str = "Provider="+dbProvider+";Data Source="+dbHost+"; User Id="+dbUser+"; password="+dbPassword+"; Initial Catalog="+dbDefault;
    getDatabase();
    }
    function getDatabase()
    {
    try
    {
    conn.Open(conn_str)
    alert(conn)
    }
    catch(e)
    {
    alert("Error creating Connection")
    }
    }
    </script>
    </head>
    <body onload="getData()">

    </body>
    </html>

  6. #6
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,626
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Instead of using your database manipulation code on the client side do it in the server side so that your web server will process whatever database manipulation script before sending the results to the client browser.

    It is not appropriate to have a database manipulating script in the client side script due to security reasons also.

    You can checkout this website which describe using JavaScript as a server-side scripting language as well as client side.

  7. #7
    Join Date
    Dec 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default connecting to client database with asp and javascript

    HI,

    Thanks for the help.
    I have tried this earlier, but the problem is with DB connections across domains.
    As per my knowledge since the application is placed on the webserver it is not possible to connect client DB from server.
    Also i have the requirement to provide an interface to the users such that they can connect to their own databases(eg: SQLSERVER) simply by providing the DB details of localhost.

    My approches so far i have done:
    1) Initially i have tried this all with asp, but it raised an issue of DB connection not possible across domains.
    2) Second i have tried this by completely migrating the application to client side using JS. but raised the problem with ActiveXobjects

    Hope u got my problem. pls help me very urgent

    Thanks in advance...

  8. #8
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,626
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    I am having difficulty with the way you are specifying your database location. Usually in a website development database will be either stored in the machine where your site resides or on another machine with which the web server machine has connectivity.

    In your case you are telling that you need to connect to the databases that are in client machine(s). Are you telling that each user has their own database in their choosen database package?

    Is this something not related to the normal web development process?

  9. #9
    Join Date
    Dec 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Connecting to client Database using ASP in IE and FireFox

    HI,
    yes, you are right. I need to manipulate the databases of client's from the server.
    Could you pls help me in what way i can proceed with this kind of requirement using ASP and JS with SQLSERVER.

    Thanks in advance. very urgent...

  10. #10
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,626
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    I think the JavaScript code that does communicate with the database in a client machine only works in Microsoft Internet Explorer as it uses Activex technology which is not compatible with Mozilla based browsers as the code runs at the client browser and the script engine of the browser is responsible for the execution.

    If you are looking for a way using which you are trying to manipulate the database of your clients/visitors, i don't think it as a reliable method for doing so as a client can disable the JavaScript of the browser at their will.

    Because of this reason all the important operations like database manipulation are done at the server-side.

    You can keep a centralised database rather than having a database on each of your clients, which is not practical at all due to so many reasons like accessibility, security, etc. If the client makes any change in the database (which can be done at their will as the database is stored in their machine) that will create problems for your script as a result you won't get the result as supposed.

    I don't know what type of application/task you are dealing with but it would be better if you redesign the current application design.

    You can post your problem in the forum so that you'll get more good ideas from the forums users and carry out your job in an efficient manner.

Bookmarks

Posting Permissions

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