使用Javascript连接SQL Server数据库 [英] Using Javascript to connect SQL Server database
本文介绍了使用Javascript连接SQL Server数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用Javascript从SQl Server 2008数据库读取一些数据。
所以我这样写:(html页面代码)
I need to use Javascript to read some data from SQl Server 2008 Database. So I wrote this:(html page code)
<!DOCTYPE html "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Database Connect</title>
<script type="text/javascript">
function loadDB(){
var connection = new ActiveXObject("ADODB.Connection");
var connectionstring="Data Source=ИЛЬЯ-ПК;Initial Catalog=C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\SIGMA_Database.mdf;User ID=Илья;Password="";Provider=SQLOLEDB";
connection.open(connectionstring);
var rs = new ActiveXObject("ADODB.Recordset");
rs.Open("SELECT Username FROM Users", connection);
rs.MoveFirst();
while(!rs.eof)
{
document.write(rs.fields(1));
rs.MoveNext();
}
rs.close();
connection.close();
}
</script>
</head>
<body onload="loadDB()">
<div id="main"></div>
</body>
</html>
但是,没有任何反应!
有什么问题?在连接字符串中有一些西里尔字母符号,可能是问题的根源还是另一个问题出错了?
However, nothing happens! What is wrong with it?There're some cyrillic alphabet symbols in connection string, can it be a source of problem?Or another thing is going wrong?
推荐答案
这是只有IE的代码,甚至在IE你必须显式允许这样的事情,请看这里接受的答案:
IE8 ActiveXObject问题
This is IE only code, and even in IE you have to explicitly allow such thing, see accepted answer here:
IE8 ActiveXObject problem
这篇关于使用Javascript连接SQL Server数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文