Binary Search | How to extract SQL data using ADODB and Javascript. If you wish to access a Microsoft SQL database, using Javascript, this can be done using ActiveX and ADODB. The code below has been used with SQL2000 & 2005. You will of course require the SQL code you wish to run as a query. This will depend on the structure of the database and the attributes you wish to retrieve. To access the database, a connection string is required. This can take many forms, best explained by examples. The punctuation is important: connStr="Provider=SQLOLEDB;Data Source='(local)';Initial Catalog='DatabaseName';Trusted_Connection='yes';"; OR connStr="Provider=SQLOLEDB;Data Source='LAPTOP';Initial Catalog='DatabaseName';User ID='sa';Password='mypassword';"; OR connStr="Provider=SQLOLEDB;Data Source='xxx.xxx.xx.x';Initial Catalog='DatabaseName'';UserID='sa';Password='*&^%$#@!';"; i.e., of the form: Provider=SQLOLEDB; // A new instance name must begin with a letter, an ampersand (&), or an underscore (_), and can contain numbers, letters, or other characters. function SQLconnect(){
Example simple query: query="SELECT x,y FROM blah-blah"; Run function if connection successful (see SQLconnect(), above). GET SQL IMAGE DATA & STORE IN FOLDER SQL stores images and other big binary data files in "BLOBS". To retrieve these and save in a non-database folder, use the following function, which includes a typical query for image data (construct yours to suit your database, of course): You can now access images by reading from RootPath, eg, "C:\\DbImages\\JohnsPic.jpg" |
|