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!