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数据库,确实令人惊叹!

 

 

posted @ 2008-08-27 19:56  LanceZhang  阅读(1506)  评论(5编辑  收藏  举报