Can JavaScript access the client's SQL database? Yes! (Access a client side MSSQL database by JavaScript)

Source: Internet
Author: User

Can JavaScript access the client's SQL database? Yes! Really!

 

Requirements: SQL Server2000 (not tested in other versions), and WMI extensions must be installed in the database (wmi SQL server administration provider, which can be found in the "x86otherwmi" directory on the SQL Server2000 installation disc)

 

Now, let's try it.CodeRight :( 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. net7.1" >
< Meta Name = "Vs_targetschema" Content = "Http://schemas.microsoft.com/
Intelliisense/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 >  

 

Although there may be no practical value, it is amazing that javascript can access the SQL Server database!

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.