JavaScript能訪問客戶SQL資料庫?能!(Access a client side MSSQL database by JavaScript)
JavaScript能訪問客戶SQL資料庫?能!真的能!
要求:SQL Server2000(其它版本沒試過),且資料庫必須安裝了WMI擴充(WMI SQL Server Administration Provider,能在SQL Server2000安裝光碟片的"x86otherwmi" 目錄下找到)
好了,接下來我們試試代碼吧:(code from http://www.devarticles.com/c/a/JavaScript/Combining-North-Pole-with-South-Pole-JavaScript-with-SQL-Server-2000/)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/
intellisense/ie5">
<script id="clientEventHandlersJS" language="javascript">
<!--
functionButton1_onclick() {
var locator = new ActiveXObject ("WbemScripting.SWbemLocator");
var service = locator.ConnectServer(".","rootMicrosoftSQLServer");
var properties = service.ExecQuery("SELECT Name FROM MSSQL_Database");
var e = new Enumerator (properties);
document.write("<table border=1>");
dispHeading();
for (;!e.atEnd();e.moveNext ())
{
var p = 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> <INPUT id="Button1" type="button" value="Button" name="Button1"
language="javascript" onclick="return Button1_onclick()">
</body>
</html>
呵呵,雖然也許沒有什麼實用價值,但JavaScript竟能訪問SQL Server資料庫,確實令人驚歎!
作者:Lance Zhang(Lance Zhang's Tech Blog)
出處:http://blodfox777.cnblogs.com/
本文著作權歸作者和部落格園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文串連,否則保留追究法律責任的權利。