You must Sign In to post a response.
  • Category: ASP.NET

    Why i am unable to connect to Sqlserver using firefox and chrome

    Are you looking for a way to connect to database using ? want to know why you are not able to connect to Sqlserver using firefox and chrome ? then read this thread to know more about it


    I want to connect to sqlserver database in ASP.NET. It's working fine only in IE, but it's not working in Other Browser like Chrome,Firefox,Safari etc..
    here is my below code.

    <script type="text/javascript" language="javascript">

    function loadDB() {
    var connection = new ActiveXObject("ADODB.Connection");
    var rs = new ActiveXObject("ADODB.Recordset");

    var ConnString = "Data Source=XXXXXXXX;Initial Catalog=XXXXXXXX;User ID=XXXXXXXX;password=XXXXXXXX;Provider=SQLOLEDB";
    var SearchValue = document.getElementById("txtSearch").value;
    var strQuery = "select Client from App_Activations where Client like '" + SearchValue + "%'";
    rs.Open(strQuery, connection);
    while (!rs.EOF) {

    $("#dvShow").append(rs.Fields.Item(0) + "<br>");


    Please help me. it's urgent.

    With Regards,
    Manoj Kumar
  • #743201
    This code is IE specific that's why you are able to run it on IE. On other browser the active X rendering is different so please use some different code.

    var fso = new ActiveXObject("Scripting.FileSystemObject");

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #743203
    The reason why it is not run in any other browser is simple, you have used 'ActiveXObject' in your code, which is purely compatible to IE, hence is will not run on any other machine.
    Why you want to connect to database using 'javascript', it may be harmful as malicious attack can get it in database, you need to use codebehind to done such coding.

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #743215
    write server side coding instead of java script. it supports all browsers. if you used java script means the code is visible for all the users. its not a good practice

  • #743224
    Is there any code to connect sqlserver database in javascript/jQuery for Chrome,Firefox,Safari..etc browser ?

  • #743230
    What you end up doing is configuring a connection pool, this is the maximum number of concurrent connections you want to hand out to users, it also allows connections to be "reused" to a point. Now in terms of the client connecting directly to the database, don't ever do that. What you want to do is configure a non-privileged user account that only has read access to your database, this will be the account that retrieves data and passes it off to the client. The critical piece is that this read-only account cannot write to the database, so it minimizes chances of data corruption.

    Now what you need to do is have your application connect to a service or some type of interface that will filter out inappropriate data, such as attacks (SQL injection), once this data has been sanitized you can then pass it to your data layer. Once inside the data layer you will open a connection and push the clean + safe data into your database. The reader account will be able to retrieve it after the transaction has been committed.

    So to recap you need at least two (2) database accounts. One that is read-only, this is for the users and one that is for doing the work this is hidden in your application and cannot be externally accessed.

    Lingaraj Varatharajan.

  • #743231

    Try with below code, but this is not good practice to connect sql from javascript, use sever side code only to connect SQL.

    var connection = new ActiveXObject("ADODB.Connection") ;

    var connectionstring="Data Source=<server>;Initial Catalog=<catalog>;User ID=<user>;Password=<password>;Provider=SQLOLEDB";

    var rs = new ActiveXObject("ADODB.Recordset");

    rs.Open("SELECT * FROM table", connection);


    Try it yourself...

    Lingaraj Varatharajan.

  • Sign In to post your comments