I’m a newbie. 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. My skill and my English are bad. I’m sorry.
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-I8T1TTH1HUYEN";
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>`