610 likes | 1.15k Views
Introduction Tutorial How to publish the contents of a database using features available in Microsoft Windows Local machine Legacy client/server Intranet/Internet Introduction “Might be a little bit heavy on the VB/ HTML side for old-time capacity planners...” Vic Soder, CMG ERB
E N D
Introduction • Tutorial • How to publish the contents of a database using features available in Microsoft Windows • Local machine • Legacy client/server • Intranet/Internet
Introduction • “Might be a little bit heavy on the VB/ HTML side for old-time capacity planners...”Vic Soder, CMG ERB • If you have ever written a COBOL program, you are overqualified for web development.
Disclaimer • All products mentioned are the property of their owners • It may possible to use these technologies to publish data in ways that were not intended, or that have licensing implications
Agenda • Scripting • Data Access Methods • Overview • Configuration Issues • Sample Scripts • ActiveX Controls • Overview • Sample Scripts • Office Web Components
Scripting • Script is the glue • Vbscript and Jscript • Legacy Windows WSH – Windows Scripting Host • Browser Client-side and Server-side
SAS M D A C A C T I V E X Browser SQL Server Script Window Access Scripting
MDAC Microsoft Data Access Components
MDAC • Universal Data Access • ODBC – Open Database Connectivity • OLE DB – OLE Database • ADO – Active Data Objects • RDS – Remote Data Services • ADO.Net - ???
ODBC • Circa 1990 • Ubiquitous drivers • Not an Object-Oriented API • Relational bias
OLE DB • COM interface • Support for broader spectrum of data repositories • Interface used by ADO • ODBC data sources accessible via “MS OLE DB provider for ODBC” • Possibly with reduced function
ADO • (currently) Highest level interface • Simplified object structure • Relies on OLE DB
RDS • Makes ADO data sources accessible across a network • HTTP, HTTPS, or DCOM • Uses Microsoft Internet Information Server as conduit
ODBC Data Sources • Control Panel Administrative Tools Data Sources (ODBC) • SAS ODBC Drivers • System Data Source • TCP Portc:\WINNT\system32\drivers\etc\services
ODBC Separate install Full SQL support Runs Proc OdbcServ instance Field name is variable label OLE DB Auto install with V8 SQL not supported Direct lib/member access Field name is variable name SAS ODBC vs. OLE DB
MSDFMAP.ini • RDS Security • C:\WinNT\System\MSDFMAP.ini • Create token to identify local data source for remote access • Determine permitted access
MSDFMAP.ini [connect default]Access=NoAccess[sql default];Sql=" “ ' <---comment this line out[connect PDB]Access=ReadOnlyConnect="Provider=sas.LocalProvider.1; Data Source=d:\PDB\Detail\“[connect SasRemote]Access=ReadOnlyConnect="Data Source=SasLocal"
Other RDS/IIS Issues • IIS uses IWAM-servername as proxy (Launch IIS Process Account) • WQExxxxx.TRC diagnostics • Recommendations (SAS) • ODBC – Start Proc OdbcServ manually • OLE DB – give IWAM-servername read permission to PDB
RecordSet Object • Set rs = CreateObject(“ADODB.Recordset”) • Methods • rs.Open, rs.Close • rs.MoveFirst, Rs.MoveNext • Properties • rs.BOF, rs.EOF • rs.Connection
Field Object • Fields collection contains Field objects, one for each column in the table • rs.Fields.Count – number of columns • rs.Fields(x).Value - value • rs.Fields(x).Name – label
Warning Code to Follow
ADO Script - WSH Set rs = CreateObject(“ADODB.Recordset”)ConnectionString = “DSN=SasLocal”Sql = “Select PCTCPUTM from PDB.System”rs.Open Sql, ConnectionStringWhile Not rs.EOF Msg = Msg + CStr(rs.Fields(0).Value) + vbCrLf rs.MoveNext endMsgBox MsgD:\Cmg2000\AdoWsh.vbs
RDS Script - WSH Set rs = CreateObject("ADODB.Recordset")ConnectionString = “Provider=MS Remote;” + _“Remote Server=http://ServerName;” + _“Handler=MSDFMAP.Handler;”+ _“Data Source=SasRemote” Sql = “Select PCTCPUTM from PDB.System“rs.Open Sql, ConnectionStringWhile Not rs.EOF Msg = Msg + CStr(rs.Fields(0).Value) + vbCrLf rs.MoveNext endMsgBox Msg D:\Cmg2000\RdsWsh.vbs
ADO Script – Client-Side <HTML><SCRIPT LANGUAGE=vbscript>Set rs = CreateObject("ADODB.Recordset")ConnectionString = "DSN=SasLocal“Sql = “Select PCTCPUTM from PDB.System“rs.Open Sql, ConnectionStringWhile Not rs.EOF Msg = Msg + rs.Fields(0).Value + vbCrLf rs.MoveNext endMsgBox Msg</SCRIPT> </HTML> D:\Cmg2000\AdoClient.htm
ADO Script – Server-Side <HTML><%Set rs = CreateObject("ADODB.Recordset")ConnectionString = "Data Source=SasLocal“Sql = "Select PCTCPUTM from PDB.System“rs.Open Sql, ConnectionStringResponse.Write("<SELECT>" + vbCrLf)While Not rs.EOFstr = "<OPTION>" + CStr(rs.Fields(0).Value) + vbCrLf Response.Write(str) rs.MoveNextWend http://.../AdoServer.asp%> </OPTION></SELECT> </HTML>
ActiveX Objects • COM subroutines • Visible and not • Microsoft and not • ProgId (OWC.Spreadsheet) or ClassId“0002E510-0000-0000-C000-000000000046” • Create them • Read/write properties • Call methods • Handle events
ActiveX – No Script <HTML><OBJECT HEIGHT=500 WIDTH=100%classid=clsid:C4D2D8E0-D1DD-11CE-940F-008029004347></OBJECT></HTML> D:\Cmg2000\NoScript.htm
ActiveX – Data Bound <HTML><OBJECT id=grid height=600 width=100%classid=clsid:0ECD9B64-23AA-11D0-B351-00A0C9055D8E></OBJECT><SCRIPT LANGUAGE=vbscript>Set rs = CreateObject("ADODB.Recordset")Set cn = CreateObject("ADODB.Connection")cn.Open "Provider=sas.LocalProvider.1;Data Source=d:\PDB\“rs.Open “System", cn, , , 512 'adCmdTableDirectset grid.DataSource = rs</SCRIPT></HTML> D:\Cmg2000\DataBound.htm
Office Web Components • Ship with Office 2000c:\Program Files\MicrosoftOffice\Office\MsOwc.dll • Spreadsheet • clsid:0002E510-0000-0000-C000-000000000046 • ProgId = OWC.Spreadsheet • Chart • clsid:0002E500-0000-0000-C000-000000000046 • ProgId = OWC.Chart • Pivot Table - OWC.PivotTable • DSC - OWC.DataSourceControl
OWC Spreadsheet • Resembles Excel spreadsheet • Visible or not • Contains one or more Worksheets • Worksheets contain cells • spreadsheet.worksheet.Cell(row,col) • Single Worksheet then spreadsheet.Cell(row,col)
OWC Spreadsheet Range • Identifies a rectangular group of cells • Used by methods that operate on groups of cells • set Range = spreadsheet.Columns(x) • object.Range(TopLeft : BottomRight)
OWC Spreadsheet API • ss.ActiveSheet.UsedRange.Clear • ss.ViewableRange = ss.ActiveSheet.UsedRange.Address • ExcelStyleCellReference = ss.Columns(Columns).Address • Set c = ss.Constants Constants available at run-time
OWC Spreadsheet Formatting • ss.TitleBar.Caption = “string" • ss.Columns.ColumnWidth = 100 • ss.Rows(x).Font.Bold = True • range.NumberFormat = "hh:mm“ • ss.Columns(x).Hidden = True • ss.DisplayRowHeaders = False • ss.ScreenUpdating = False
Populate Spreadsheetfrom RecordSet Row = 1While Not rs.EOF Col = 1 While Col <= rs.Fields.Countss.ActiveSheet.Cells(Row, Col).Value = rs.Fields(Col - 1).Value Col = Col + 1 Wend Row = Row + 1 rs.MoveNextWend
Populate Faster Set field = rs.FieldsSet cell = ss.ActiveSheet.CellsRow = 1While Not rs.EOF Col = 1 While Col <= rs.Fields.Countcell(Row, Col).Value = field(Col - 1).Name Col = Col + 1 Wend Row = Row + 1 rs.MoveNextWend
OWC Chart • General purpose charting functions • 45 chart types • ChartSpace - one or more charts • Careful with terminology • Series – points to be plotted as a group • Value axis is vertical (y) • Category axis is horizontal (x)
ColumnBar Line Pie Scatter Bubble Area Doughnut RadarStockPolar ClusteredStacked Stacked100MarkersSmooth ExplodedFilledHLC OHLCCombo Chart Types
OWC Chart API • Set cs.DataSource = ss.Object Chart data will come from spreadsheet • Set chart = cs.Charts.Add() Add a chart to the chart space • cs.Clear Clear all charts in the chart space • Set c = cs.Constants Constants available at run-time