用JavaScript访问客户SQL Server数据库
2008-08-28 09:57:26 来源:WEB开发网JavaScript能访问客户SQL Server数据库?能。
要求:SQL Server2000(其它版本没试过),且数据库必须安装了WMI扩展(WMI SQL Server Administration Provider,能在SQL Server2000安装光盘的"x86otherwmi" 目录下找到)
好了,接下来我们试试代码吧:
<!DOCTYPE HTML PUBLIC "-//W3C//DTDHTML4.0Transitional//EN">
<html>
<head>
<title></title>
<metaname="GENERATOR"content="MicrosoftVisualStudio.NET7.1">
<metaname="vs_targetSchema"content="http://schemas.microsoft.com/
intellisense/ie5">
<scriptid="clientEventHandlersJS"language="javascript">
<!--
functionButton1_onclick(){
varlocator=newActiveXObject("WbemScripting.SWbemLocator");
varservice=locator.ConnectServer(".","rootMicrosoftSQLServer");
varproperties=service.ExecQuery("SELECTNameFROMMSSQL_Database");
vare=newEnumerator(properties);
document.write("<tableborder=1>");
dispHeading();
for(;!e.atEnd();e.moveNext())
{
varp=e.item();
document.write("<tr>");
document.write("<td>"+p.Name+"</td>");
document.write("<td>"+p.SQLServerName+"</td>");
document.write("</tr>");
}
document.write("</table>");
}
functiondispHeading()
{
document.write("<thead>");
document.write("<td>Name</td>");
document.write("<td>SQLServerName</td>");
document.write("</thead>");
}
//-->
</script>
</head>
<body> <INPUTid="Button1"type="button"value="Button"name="Button1"
language="javascript"onclick="returnButton1_onclick()">
</body>
</html>
呵呵,虽然也许没有什么实用价值,但JavaScript竟能访问SQL Server数据库,确实令人惊叹!
Tags:JavaScript 访问 客户
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接