Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

361
Views
Create connection to SQL Server using JavaScript in HTML (ASP.NET MVC)

I've watched this video https://www.youtube.com/watch?v=Rr9RE05rw4E and followed this. But I don't have a response in my comment. I have a problem with:

Error creating connection.

I don't know why I can't access the database. My syntax is the same as this video so I don't know what is going wrong.

Here is my code

<script type="text/javascript">
        var conn = new ActiveXObject("ADODB.Connection")
        var conn_str = ""
        var db_Host = ""
        var db_User = ""
        var db_Password = ""
        var db_Provider = ""
        var db_Default = ""
    function Show_Data() {
        db_Host = "LAPTOP-I8T1TTH1\HUYEN";
        db_User = "sa";
        db_Password = "password";
        db_Provider = "SQLOLEDB";
        db_Default = "DEMO";
        conn_str = "Provider="+db_Provider+";Data Source="+db_Host+";User ID="+db_User+"; password="+db_Password+ "; Initial Catalog="+db_Default;
        show_data_from_database();
    }
    function show_data_from_database() {
        try {
            conn.Open(conn_str)// open the connection
            //alert
            var reader = new ActiveXObject("ADODB.Recordset");
            var strQuery = "SELECT * FROM user";
            reader.Open(strQuery, conn);//fetch the data
            reader.MoveFirst();//move to the first row
            while (!reader.EOF)//read until the last row of data
            {
                document.write(reader.fields(0) + "&nbsb;&nbsb;&nbsb");// print to the screen
                document.write(reader.fields(1) + "&nbsb;&nbsb;&nbsb");
                document.write(reader.fields(2) + "&nbsb;&nbsb;&nbsb");
                document.write(reader.fields(3) + "<br/>");
                //alert(rs.fiels(0));
                reader.movenext(); // move to the next row
            }
        }
        catch (e) {
            alert("Error creating connection")
        }
    }
</script>
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!