JavaScript能訪問客戶SQL資料庫?能!(Access a client side MSSQL database by JavaScript)

來源:互聯網
上載者:User

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資料庫,確實令人驚歎!

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.