Thursday, 20 March 2008

Chapter 5: Debugging & Error Handling with SSIS Packages.

Create control flow by using the control flow designer.



  • Can co-ordinate txns with package restart - can be configured to restart from pt of failure when pckg rerun.
Configure txn handling for packages, containers, tasks.



  • DTC - start svc + tasks that are to be part of txn must work natively with DTC svc.
  • TransactionOption - Required.
  • Txns work at control fow lvl, NOT data flow.

Connecting Control Flow Objs with Precedence

  • Precedence constraints - control flow connectors bet. tasks & containers. NOT in data flow. Connectors there are 'data paths'.
  • solid lines - && precedence -
  • dashed lines - precedence - task will run when either of the precedence conditions is met.
  • functional symbols - an SSIS expression has been embedded in the constraint for evaluation.


Set checkpoints to define restart pts

  • restart @ point of failure.
  • Enable pckg to use chkpts - PackageProperty.SaveCheckpoints -> TRUE, PackageProperty.CheckpointFileName - supply, PackageProperty.CheckpointUsage - IfExists - pckg runs fom beginning if file not present, or run from identified pt where exists. (If CheckpointUsage = Always, file must be present or pckg will not start).
  • Set checkpoints at various stages of the pckg -


Create Event Handlers

  • -> Event Handlers tab in pckg designer, select executable, select event handler event.
  • event handlers assigned to a particular scope will propogate downwards to child events when the event fires.
  • Capturing err. info. with OnError event - capture sys. variables e.g. ErrorCode, ErrorDescription, SourceName (i.e. the task).
  • Event handlers can be turned off for any task/container - DisbaleEventHandlers -> TRUE.



Implement error handling

Handle errors by configuring data flow paths

  • Data paths - output rows that have successfully gone thro a component, as well as errored rows where error output is set to ignore failure for said task.
  • Using error paths to route failed rows - red connectors. Contain data rows that fail in a component, when the error rows are set to be redirected. To use, configure the task's error output.
  • not all components use error paths e.g. Multicast.
  • error output - 3 options: Ignore Failure, Fail Transform, Redirect Row.
  • error handling options are available for entire row + per col.



Handle errors by configuring control flow paths

Debug Packages

Debug progress reporting

  • Even after an error, other components in the pckg might still be executing.
  • Allowing mult. errs - MaximumErrorCount property -



View intermediate results by using debug windows

Examine the package state by setting breakpoints

  • Control flow debugging - set bpts, which will pause the control flow execution so that you can observe the execution state.
  • bkpts - only in control flow.



Wednesday, 19 March 2008

Chapter 4: Developing SSIS Packages.

Create a Package -

Use BIDs -
  • Needed because 'more complicated' packages cannot be created thro I/E Wizard.
  • Need to create a set of co-ordinated pckgs.

Use SQL's Import/Export Wizard -
I know this already!!

Create data flow by using the data flow designer -

Configure sources & destinations -
  • Navigate to data flow tab.
  • 3 types of obj in toolbox:
    1. Data flow source adapters - along with destinations, they use package connections. Only raw file adapter doesn't use PC.
  • 2. Data flow transforms - a transform performs an op. on one row at a time or several rows at a time. Types of tranforms - a) Logical row-lvl transform - performs op on rows without needing other rows. b) Multi-input or multi-output transforms - either can work with > 1 input or generate >1 output. Used to combine or branch data. Merge & Merge Join require sorted inputs. These 2 transforms will wait for rows from either input based on the defined sort order, to preserve the sorted output. Thus rows may not immediately be sent out on the output path. c) multi-row transforms - perform work based on criteria from multiple input rows, or generate multiple output rows from a single row. Such transforms can be more intensive in operation and memory overhead. Sort, Aggregate - these are blocking transdforms - all output rows are blocked, allowing the tranform to perform the work before sending rows downstream. d) Advanced data-prep transforms - e.g. script component, fuzzy lookup.
  • 3. Data flow destination adapters - Set ValidateExternalMetadata property -> false if e.g. a destination tbl is not available at design time, as it is created during execution. OLE DB Destination Adapter - can be configured for bulk insert, otherwise data is inserted 1 row at a time.
  • connect srcs, tranforms & destinations by connecting data paths (green or red).
Configure transformations -

Create control flow by using the control flow designer -
  • The control flow is the workflow engine & contains control flow tasks, containers & precedence constraints. In BIDs we define control flow objs with the control flow designer (1st tab).
  • (Dataflow is directly related to processing & transforming data from sources -> destinations).
  • 3 primary types of control flow objs:
  • 1. Control flow tasks - workflow objs that perform operation-lvl jobs.
  • 2. Containers - provide a grouping mechanism for tasks.
  • 3. Constraints - Allow one to connect tasks & containers and thus define exec order + precedence.

Control Flow Tasks -

  • Each CFT has an editor to configure it.
  • Pckg must contain at least 1 task.

Control Flow Containers -

  • A container allows one to grp tasks to control parellelization, ordering, logging & txns.
  • Containers also provide the ability to execute the tasks within them several times based on iterative requirements.
  • Sequence container - Lets you organise subordinate tasks by grping them together, & then apply txn or logging to the cont.
  • For Loop container - As Seq. Cnt. but also allow for running of tasks therein to be run multiple times, based on an eval. condition e.g. looping from 1 to 10.
  • ForEach Loop Cont. - instead of providing a condition expr. for looping, you loop over a set of objs such as files in a folder. Can iterate over diff. types of objects.
Sequence tasks by using precedence constraints -

Organize tasks by using containers -

Manage SSIS package configurations -

Connect to different data source types by adding connection managers -
  • Data Sources - An SSIS Project object. live at project lvl and are found in Solution Explorer under logical folder 'Data Sources'. Once an existing data src is changed you need to open each package to synch the conn string inside each pckg, with the data src.
  • Connections - scoped @ pckg lvl. Connections can be based on project data sources (New Connection from Data Source...) or can stand alone within pckgs.

Tuesday, 18 March 2008

Chpater 3: Migrating to SQL Server 2005 BI Components

Definitions
Measures - the numbers that are analysed. E.g. sales amts, inventory counts, account balance amts.
Dimensions - qualify whats being analysed. E.g. if analysing sales amts, then the following dimensions will relate to each sale: pdt, customer, sale date & store.
Attributes - Dimensions are made up of attributes. They provide detailed descriptors about the dimension. e.g pdt dimension will have attributes: Category, Model, Size & Pdt Name. You can summarize/analyse data at an attr lvl.
Hierarchies - attr's combine together to make hierarchies. (Yr -> Qrtr -> Mnth -> Day).
Cubes - contain dimensions, attributes, measures.

The 2 features with changes that have the largest impact on migrating are attributes and cubes.


Managing SSAS


  • In-place migration - when install 2005 on same server on which def. instance of 2000 already installed. The 2005 installation process wil auto invoke the in-place upgraqde, thus existing cubes will be auto migrated.
  • side-by-side migration - install 2005 on a new server OR same server as named instance. (TIP: install a named 2005 instance alongside an unnamed 2000 instance. Then after successful auto migration of cubes uninstall 2000 and rename 2005 to default instance).
Migrate from SSAS 2000 to SSAS 2005 ~ Migration Wizard

  • Attribute Changes - in 2000 a dim. cld only contain 1 hierarchy. In 2005 a dim. can have >=0 hierarchies.
  • Cube changes - In 2000 only 1 'fact' tbl. In 2005 >=1 fact tbl. In 2000 whilst cubes can be combined into virtual cubes, there are limitations on how the fact tbls can relate to one another.

  1. Run on server hosting 2005. Need lcl or network access to 2000 cube.
  2. IDs incompatibilities.

Post Migration considerations -

Migrate to SSIS packages

  • DTS & SSIS - diffs -
  • DTS is workflow engine with a few data transform fntns. SSIS - enterprise-lvl ETL tool with richer workflow engine, better tranform engine, + ability to perform data operations.
  • Workflow-drive Vs Dataflow driven.
  • synchronous data processing Vs asynch data-processing.
  • one-to-one data copies Vs many-to-many data processing.
  • Scripting for advanced operations Vs minimal scripting due to broad capabilities
  • all or nothing Vs package restartability + txns support

  • Executing & Managing DTS in SQL 2005 -
  • Installation Runtime - when installing 2005, the Advanced Options allow one to choose to include the DTS Runtime Engine as part of the 2005 installation.
  • SSMS - Can manage + design + edit (install DTS Designer components) DTS packages in 2005 Mgmt Studio. Store DTS pckgs in msdb - Mgmt\Legacy\DTS.
  • Execute Package Task - exec DTS pckg from within SSIS pckg.

  • Running Package Migration Wizard -
  • can select mult. packs to migrate.
  • Wizard logs progress to a flat file.
  • If invoked wizard from within BIDS, the output SSIS pckgs will be auto added to the existing project.

  • Post-Migration Steps -
  • Some DTS func. does not migrate well:
  • Dynamic Property tasks in DTS do not get migrated. Instead the details of the dynamic property are entered into a Script task as comment lines.
  • Analysis Services 2000 Processing Task not supported in SSIS. Will need to call an .exe or use Script Task.
  • UDL (Universaal Data Link) files not supported in SSIS - so if DTS pckg contains a conn. pointing at UDL file conn. in SSIS will need changing.
  • Data Pumps that involve scripting or certain conns (e.g. Excel) will get embedded in an Execute DTS 2000 Package Task.
  • Taking Advantage of SSIS features -
  • Convert any Exec DTS 2000 Tasks -> Data Flow Task.
  • Change Exec SQL Tasks -> Data Flow Tasks - DTS relies heavily on relational db engine to perform transforms, and thus you can reduce need for staging tbls.
  • Add error handling.
  • Add checkpoints - i.e. built-in restart features, which allow you to start a package fro ma prev. point of failure.

Create a package

Use the Package Migration Wizard

Monday, 17 March 2008

Chapter 2: SSRS, SSAS configurations & settings

SSAS, SSRS - require the setup of server-side config properties + instance-wide settings.

Configure SSAS

Configure Query/Error Logging

  • Log\FlightRecorder - an error and activity log for SSAS. Set Enabled -> TRUE. Rsetart for chnage to take effect. By def., it does not capture queries. TraceDefinitionFile property - define your own trace, capture the defn, and override the default capture.
  • Log\QueryLog - enable capture of queries that are run against any SSAS db in the instance. You can use captured queries to optmiize aggregation.




Configure Disk Allocation

Configure server and db roles and permissions


> install of SSAS instance, the SSAS svc needs configuring with SSAS security roles for administration.
Setting SSAS Admin Roles and Permissions:
  • There are 2 primary security roles:
  • 1. Server Role - provides access to complete SSAS server fntns, incl. data & processing. Provides complete SSAS access to assigned users. Manage users/grps assigned to role ~ Mgmt Studio. Members of the lcl admin grp on the same server as the SSAS instance are automatically added to Server role, although this grp does not appear on the server role list.
  • 2. Database roles - define db-lvl admin/mgmt tasks and end-user data access. General pg - name + describe the role + assign db permissions: Full Control (Administrator), Process db (user is limited to processing the db in which the role is created), Read definition (lets a role member see the full definition of a db - no data-access or processing rights). ~ Membership tab, can manage lcl/domain users/grps w.r.t the role.
  • SSAS uses Windows Auth only - no SQL Auth option => SSAS security can olny be assigned to domain/local users+grps.



Configure an SSRS infrastructure

If SSRS is installed with def. config -> no further config req.
If installed 2nd (named) instance OR need to configure for Internet deployment -> special config req.

Configure SSRS for Internet deployment
1. Create virtual directories in IIS - The Web Svc that SSRS uses for report mgmt, publishing + rendering is located in Report Server Virtual Directory. (Def. name - Report Server).
2. Create the virtual directory for the Report Manager - Report Mngr is the web-based mgmt tool for setting up dirs + managing security on the web site.


choices:

  1. enforce secure conns. to SSRS,
  2. place SSRS virtual directories on the Web for Web deployment + reporting.
  • SSRS allows 4 security lvls for comm. -> Report Server, from port 80 HTTP conn to SSL.
  • For SSL conn, change RSReportServer.config -
  • Also define IIS AUTH. MTHD FOR vIRTUAL dIRECTORY ACCESS - bASIC, wINDOWS, aNONYMOUS aCCESS. Windows Auth is recommneded for security, but Basic Auth. with SSL will provide secure connections from machines that are not logged onto your corporate domain.

Where SSRS access from Internet (e.g. for Internet deployment & rendering), prevent security risks:

  • Report Server db should remain behind a firewall.

Create and configure SSRS instances by using the Reporting Services Configuration Manager tool

  • For Server setup & management.
  • SSRS server component includes RSCM tool, a UI admin tool for configuring SSRS server settings.
  • If IIS installed, the following steps will enable instance for development & reporting:
  • 1. Create virtual directories in IIS - The Web Svc that SSRS uses for report mgmt, publishing + rendering is located in Report Server Virtual Directory. (Def. name - Report Server).
  • 2. Create the virtual directory for the Report Manager - Report Mngr is the web-based mgmt tool for setting up dirs + managing security on the web site.
  • 3. Windows/Web Svc Identity - select local/domain acc/grp to run windows/asp.net svc.
  • 4. Setup SSRS repository dbs - these dbs are used by SSRS to store rpt defs, data sources, virtual folder for Report Mngr. Database Setup -> select local/remote OR create new: db names - ReportServer, ReportServerTempDB.
  • 5. Initialization - red X? - -> & click Initialize btn.
  • 6. Start SSRS Instance - Server Status settingd pg, click Start to start svc. Verfiy instance running - connect to Report Manager virtual dir - http://localhost/reoprts
  • 7. Backup encryption key - needed to recover contents of an installation. -> Encryption Keys pg - back up.
rsconfig.exe

  • an admin command-line tool for managing SSRS server settings.
  • manages the instance's conn. -> repository db (i.e. Report Server), + for setting up def. credentials for unattended rpt exec. (e.g. when triggered by an SSRS event such as a scheduled rpt) against dbs.

rskeymgmt.exe

  • for mgmt of the encryption keys for ops such as backup, restore, create.
  • SSRS uses symmetric encyption keys to secure & encrypt content in the Report Server db.


Install an SSRS infrastructure

Manage private keys for encryption

  • rskeymgmt.exe - another command-line utility.
  • used in mgmt of symmetric encrytion keys, that SSRS uses to secure + encrypt content in the Report Server db.
  • used for general mgmt of encryption keys such as backup, restore, delete.
  • Must be run locally - cannot be run against a remote svr.





Monday, 10 March 2008

Chapter 1: Installing SQL Server 2005 BI Tools

Install SSAS
License terms - agree.
Software Prerquisities: .NF 2.0, SS Native Client. IIS for SSRS. Installer will prompt re. these + others.
System Config Check - config changes needed <>
Pdt key.
Instance name - name of this instance on machine. Instances apply to Database Engine, SSAS, SSRS.
Def. Instance - componentns sel. will be installed with no name => conn. strings only consist of server name.


Install multiple instances

  • Setup.exe from Servers folder or installation setup files folder.
  • Why mult. instances - diff. vers/editions on same physical machine. Mult. installations, each at diff svc pack lvls.
  • Service Account - choose sys. security account under which to run each SQL service: a) customise for each svc acc., b) built-in - local (full access), network (limited access), c) domain user account d) start at end of setup (+ whenever server is started).

Install a clustered instance

  • MSCS - Microsoft Clustering Services.
  • SSAS is cluster-aware & can be installed in an MSCS installation.
  • shared-nothing model - the drive volumes (ones that hold the db + cube data) can only be controlled by 1 machine at a time in the cluster.
  • Automatic failover - if SQL Server service stops on 1 machine, the drives are fully controlled automatically by another in the cluster.
  • nodes - servers in a cluster.
  • failover instances - db instances/AS instances in an MSCS installation.
  • 1. Install SSAS on a cluster node - SQL will recognise its env. and enable the option to install a failover instance. Check 'Create an AS Failover Cluster'. (option not available when installing on a non-cluster machine).
  • 2. Instance Name - default or named.
  • 3. For failover cluster instance, must provide a Virtual SQL Server name. \ - identifies node. This qualified server name will failover with the svc, and conn. strings will be able to access SSAS regardless of the node on which SSAS is running on.
  • 4. Virtual Server Config pg - assign IP address for each subnet. IP addresses too failover. Virtual SQL Server name + IP address(es) must be unique on netwoerk. The virtual SQL Server name cannot be the same as the physical server name or the cluster name.
  • Available Cluster Group - shows all available cluster groups into which you can install SSAS. MSCS groups resources that have dependencies & therefore need to failover together: drive volumes, server names, IP addresses. Only cluster groups with shared drives are available - SSAS requires data to be stored on a shared drive for clustering.
  • Cluster Nodes Config Pg - chose nodes on the cluster on which SSAS can failover.
  • Service Accounts - need to have same rights on all nodes of the cluster - thus must be a domain account.
  • Domain Groups for Clustered Services - enter domain + grp that SSAS will use.

Install SSRS infrastructure

  • When configured with def. settings on the def. instance, SSRS ready to use at end of install. You get: 2 dbs - ReportServer, ReportServer-TempDB (for catalog storage + data caching), 2 virtual servers in IIS - Reports, ReportServer - used for Report Manager Web Interface + SSRS Web Svc.
  • If need 2nd instance name it (or use def. if prev. was named).
  • Why 2 instances?: 1. if you have strict security reqs a 2nd instance allows separation of site-lvl security bet mult. groups of administrators. 2. if you have limited hardware for dev., test, & prod svrs, you can use mult. instances on a single server to simulate mutl. environments.
  • Manual Configuration (~ Rep. Svcs Config Mnr tool).

Install multiple instances of SSRS


Practice Q's
Exercise - Install Prerequisites & Components
  • IIS - check selected.
  • Accept Licence, install prerequisites, Ssytem Config Check - correct if necessary.
  • Enter name.
  • Components to Install - 'Advanced' for installing Sample dbs + sample code & apps.
  • Default instance.
  • Service Account - built-in network service for limited access.
  • Auth Mode - windows
  • Collation Settings - default
  • Report Server Installation Options pg - install def. config.
  • During setup, whilst you can define a named instance, it will apply to all the features selected during that installation. To install different components with diff. named instances, you will need to run the installation multiple times, once for each unique instance name.
  • SSAS - works only with Windows auth, & there fore does not have capability for mixed mode or SQL Server Auth.
  • After Finish - configure Samples.
  • install most recent svc pack - x86 == 32-bit sys, x64 == 64-bit sys. If you have multiple instances of db engine, SSRS, SSAS installed on single machine, you can selectively chose you can select instances to which svc packs will be applied. Tools & SSIS are not instance-aware.
  • SSAS can only use MSCS with nodes that are connected to the drive subsystem.





Friday, 7 December 2007

Chapter 11, lesson 3: Using Declarative and Imp[erative Security to Protect Methods.


  • CAS - declarative - compiler performs security checks prior to running code.
  • CAS - imperative - code itself performs checks and controls what happens.
  • SecurityAction.Demand, CodeAccessPermission.Demand() - checks an assm's caller for permissions.
  • SecurityMnager.IsGranted() - checks whether an assm itself has particular CAS perms.

Techniques for Limiting Permissions

  • use CAS assm decl to restrict perms granted to assm as a whole.
  • Then control perms on a more granular lvl by restricting perms within mthd decl + using imperative stmts.
  • EXAM HINT: use RequestRefuse(==Deny) and RequestOptional(==PermitOnly) for assm decl, and Deny and PermitOnly for mthds.
  • Exception handling - revert to PermitOnly (say for logging) and then revert.

  • Assert() - on a perm, it means that any code calling the mthd on which Assert is invoked is vouched for - it does not need said perm itself.

Tuesday, 27 November 2007

Chapter 11, lesson 2: Using Declarative Security to Protect Assemblies.

Because CAS can restric permissions given to an app., you must write apps to run in a partially trusted security context.

Use declarative CAS demands - ensure that assm has all necessary permissions but none that it does not require.

Reasons to use CAS Assm Decl

  • To ensure that the runtime will never run your app without granting access to all required resources - if user attempts to run app and CAS security policy does not grant a required permission, an exception is thrown. Use SecurityAction.RequestMinimum - to declare all CAS perms required by app.
  • To create a sandbox for app to ensure an attacker does not manipulae it to access unintended resources - use CAS decl to reduce your assms

Classes for CAS Permissions

  • For each type of resource (e.g. files/folders, printers, network access,...) that can be restricted by CAS there is a .NF class.
  • Permission Attribute classes - inherit from CodeAccessSecurityAttribute class.
  • Action property - specifies how the runtime will interpret the permission. Set to...
  • 1) SecurityAction.RequestMinimum - requires a perm. for assm to run. If assm lacks specified perm then runtime throws exception.
  • 2) SecurityAction.RequestOptional -
  • 3) SecurityAction.RequestRefuse -
  • NOTE: CAS is significant only for partially trusted assmebles. The runtime completely ignores CAS decl for fully trusted assemblies.
  • combine RequestMinimum and RequestOptional - for non-negotiable permissions for 1 thing, but nothing else required.
  • UIPermission, Unrestricted = true - for debugging + RequestOptional.

Friday, 23 November 2007

Chapter 11, lesson 1: Understanding Code Access Security.

Code Access Security (CAS) - enables users to control permissions that individual apps have. Developers thus have to create apps that work with restricted permissions.

Can also use CAS as a developer - by restricting which calers can use your code + forcibly limiting your app to a restricted permission set.

---
  • What is CAS - a security system that aloows administrators + developers to control application authorization.
  • can control auth to following resources: file sys., registry, printers, event logs, sending web requests, whether app can make DNS requests.
  • CAS can only be applied to managed apps - ones that use the .NF runtime. Unmanaged apps limitied only by O.Ss role-based security (RBS).
  • CAS identifies and assigns permissions to apps rather than to people.
  • CAS IDs assembiles ~ evidence.
  • evidence - location where assm is stored, a hash of assm code, assm signature.
  • An assembly's evidence determine which code group it belongs to.
  • code groups - grant an assm a permission set.
  • evidence - info that runtime gathers about an assm to determine which code group it belongs to e.g. folder or web site that it runs from, digitial signatures. It's info that provs identity and describes an assm as deserving a certain level of trust.
  • types of evidence - appn dir (in whcih assm resides), hash of assm, publisher (their digitial signature thus IDs software developer), Site (from which assm was downloaded), Strong Name, URL (from where downloaded).
  • host evidence - describes assm origin.
  • assm evidence - custom user or develoer-provided evidence.
  • Permission - a CAS access control entry e.g. File Dialog - determines whether an assm can prompt user with the Open dialog box. There exist 19 permissions. You can add custom permissions.
  • Permission set - CAS ACL - a group of permissions that apply to apps falling under a particular group. (e.g. LocalIntranet Zone contains more permissions that Internet). .NF has 7 default permission sets.
  • code groups - authorization devices that associate assm with permission sets. Membership to a code group is not set manually - it is determined by the evidence that you specify as the code group's membership condition.
  • Internet_Zone code group - membership condition - host presents Zone evidence + Zone evidence IDs assm as being in Internet zone.
  • A code group must be associated with a permission set.
  • You can only specify only a single type of evidence and a single permission set for a code group.
  • An assm can be a member of mult. code groups.
  • union of permsiions - assm will receive perms as union of all code grps.
  • security policy - a logical grouping of code groups and permission sets.
  • security policy - allow administrators to configure CAS settings at 4 lvls: Enterprise, Machine, User, App Domain.
  • Enterprise Security Policy - configured ~ Active directory svc.
  • Intersection of the permission sets - rutime evalutes Enterprise, Machine & User levels separately, and grants assm minimum set of perms.
  • .NF Configuration Tool - to grant/restrict an assm perms: 1. Evaluate assm to determine which code grps it is a member of, 2. eval assm to det. perms it will be assigned, 3. adding new perm sets, 4. adding mew code groups, 5. increasing an assm's trust.
  • CAS wokrs on top of OS security - if CAS grants an assm access to write to a folder but the user running the assm does not have that perm, then assm cannot write.
  • CAS Policy Tool - caspol.exe - to examine/modify machine/user/enterprise-lvl code access policies.

chapter 10, lesson 4: Detecting Management Events.

.System.Management namespace - tools to monitor + manage the system, devices and apps ~ WMI technology.

Enumerating Management Objects
  • DirectoryObjectSearcher obj - to programatically access resources ~ WMI.
  • mimics SQL.
  • To execute query:
    1. ConnectionOptions (UserName, Password). 2. instance of DirectoryObjectSearcher, 3. Instance of ManagementScope obj - set path 4. Instance of ObjectQuery obj., 5. ManagementObjectCollection = DirectoryObjectSearcher.Get()
  • enumerating logical drives - specify target - e.g. Win32_LogicalDisk.
  • enumerating network adapters - Win32_NetworkConfiguration - new ManagemmentObjectSearcher("SELECT * FRO MWin32_NetworkConfiguration");
  • enumerating windows services - Win32_Service - ManagementObjectCollection AllObjects = DemoSearcher.Get();

Wednesday, 21 November 2007

chapter 10, lesson 3: Monitoring Performance.

...for fixing perf probs like slow/sluggish UI, network access, db connectivity,...

  • Process class - can ref O.S process running ol local or remote machine.
  • Enumerating processes -
  • 1) GetCurrentProcess(),
  • 2) GetProcessById() - if process not found, ArgumentException thrown.
  • 3) GetProcessByName(),
  • 4) GetProcesses() - ArgumentException the 'catch-all' exception out of the set that could be couaght here.
  • PerformanceCounter class - for comparing baseline measurements against current measurements.
  • There exist built-in perf counters - dont reinvent the wheel!
  • CounterCreationData class - a container obj of props needed for PerformanceCounter obj.
  • PerformanceCounterCategory class - manage/manipulate PerformanceCounter objs + their categories. (See if given perf counter exists and if not, create it).

chapter 10, lesson 2: debugging and tracing.

Debug, Debugger classes - more efficient than stepping through code - less time consuming.

Debugger Class
  • enables comm with a debugger app.
  • Break() - equiv of setting bk'pt manually.
  • Log() - posts info to the attached Debugger, if present. To listener objs attached to debugger.
  • Listener - DefaultTraceListener - take Log mthds and write as text to specified target.

Debug Class

  • more granularity than Debugger.
  • Assert() - for true/false conditions - if condition isn't true it will break into the debugger automatically.
  • in release build no debug commands are compiled in so no perf degredation.
  • Fail() - doesn't use an evaluation - simply breaks at offending line and outputs failure msg.
  • Write(), WriteIf()...

Debug Attributes

  • DebuggerBrowsable attr - [DebuggerBrowsable(DebuggerBrowsableState.Never)]
  • DebuggerDisplay - configure top line for class in Locals window.
  • DebuggerHidden - stops bk'pt being set inside anything it decorates.

Monday, 19 November 2007

chapter 10, lesson 1: logging events.

  • create an event log - EventLog class. 1 or 2 actions, then use static mthds, else create instance.
  • writing - EventLog.WriteEntry() -
  • built-in logs - Aplication, Security, System logs.
  • iterate thro entries - Entries property - contains EventLogEntry properties.

Chapter 9, Lesson 4: Configuration Management.

... e.g. specifying what vers of runtime app needs, or telling app what db to connect to.

Getting/Storing settings
  • ConfigurationManager class - retrieves config settings.
  • ConfigurationManager.appSettings - exposes AppSettings.
  • ConfigurationManager.ConnectionStrings - exposes conn strings
  • ConfigurationManager.GetSection(\
    ) - rets Object.
  • ConfigurationManager.Save/SaveAs - provided... 1) ConfigurationSection.SectionInformation.ForceSave = true; 2) filename: AppName.exe.config.

Implementing Config Interfaces

  • ConfigurationSection class - replaces the deprecated IConfigurationSectionHandler interface.
  • 1) Create section in config file - decl + impl outside of all other config elts, 2) retrieve section programatic\lly - ConfigurationSectionGroupCollection gps = config.SectionGroups;
  • how to handle section? create class that impl IConfigurationSectionHandler, and impl. Create() mthd. The retrieve using ConfigurationManager.GetSection, as above.

.NF 2.0 mthd, without impl config int - r/w directly from custom config section.

  • 1) Create section in config file - decl + impl as above, 2) use ConfigurationClass as base class from which to derive classes to consume these values.

Chapter 9, Lesson 3: Using the .NF Config Tool.

...a visual tool to manage most aspects of assm config.

  • luanch it - under Admin Tools.
  • Manage the assm cache - 1) view assm in GAC, 2) add string-named assm to GA.C
  • Manage Configured Assm - 1) view configured assm, 2) Configure an assm.
  • Manage Individual Apps - 1) adding app to configure.
  • Configre an assm - Binding Policy - chnage binding redirections (switching release vers), Codebases - Security Settings

Thursday, 15 November 2007

Chapter 9, Lesson 2: Creating an Installer.

  • Setup and Deployment project types do not cover all scenarios - then create custom installer, using Installer class.
  • Such custom insallers can then be used as part of S&D proj., or installed ~ InstallUtil.exe

Using Base Installer

  • 1) derive class from base Installer.
  • 2) Override Install, Comit, Rollback, Uninstall mthds.
  • 3) Add RunInstallerAttribute to derived class, and set runInstaller param to true.
  • 4) Put derived class in assm with app to install.
  • 5) Invoke installers - i) InstallUtil.exe, ii) AssemblyInstaller/ComponentInstaller for programtic equiv.
  • 6) InstallEventHandler delegate - to facilitate Commit - wire-up Committing, Committed events in constructor.
  • 7) Installers property - ret. an instance of InstallerCollection. Can add mult. installers to a single assm. - mult. installers that do mult. things.

Chapter 8, lesson 3: Creating Windows Services.

  • WS - runs an assembly in the background without any user interaction. Run in own user session.
  • WS - can be automatically started on reboot, even if user does not log on.
  • 1. Cannot be debugged in VS. Must install, start, then attach debugger to service's process.
  • 2. Must create installation component for service apps - they install + register the svc on the server + create entry for svc with Windows Svc Control Manager.
  • 3. runs in a different 'window station' than the interactive station of the logged-on user. No dialog boxes + raise errors to event log, not UI.
  • 4. run in own security context. svc running under system account has more privileges than one under user account.

Creating a Service Project

  • There exists a Wisndows Svc app template in VS.
  • inherits from ServiceBase class.
  • OnStart, OnStop.
  • Add installers - 'Add Installer link in VS' - adds class with 2 - one to install process...

Implementing a Svc

  • ServiceBase.ServiceName property - set. ServiceName not friendly name - used by O.S. Must be unique.
  • OnStart - must not loop as has to return to O.S.
  • OnPause, OnContinue, OnShutdown. Optional.

Create an Install Project for a Service

  • Cannot simply run a svc exe. Must be installed <>
  • ServiceInstaller class - defines svc desc., display name, svc name, and start type.
  • ServiceProcessInstaller class - defines svc acc. settings. Security context set ~ Account property - 1. LocalService - nonprivileged user, 2. NetworkService - can authenticate to another comp on network, 3. LocalSystem - unlimited privileges, presents computer's credentials to any remote server.
  • VS automatically generates both above classes.

Wednesday, 14 November 2007

Chapter 8, lesson 2: Configuring Application Domains.

Configre app domains to create customized envs for assemblies.
Most important application - restricting permissions to reduce risks associated with security vulnerabilities.

Use App Domain to launch assm with limited privileges
  • Restricting permissions of an app domain greatly reduces the risk that an assm you call will perform some malicious action.
  • Defense-in-depth - providing multiple levels of protection.

Using 'Evidence' to configure App Domains

  • Code Group - a logical grouping of code that has a specified condition for membership

Chapter 8, lesson 1: Creating Application Domains.

assembly - defn - a software component that support plug-and-play. A .NET assembly is a deployable unit. An assmebly is a logical DLL oe EXE and a manifest is a detailed description (metadata) of an assembly.

  • Application Domain - a logical container. Allows mult. assemblies to run within a single process, but prevents them from accessing other assemblies' memories.
  • App Domain - like a process - separate memory spaces + access to resources.
  • App Domain - more efficient than processes - allow mult. assemblies to run in separate app domains, without overhead of launching separate processes.
  • App domains - keep assemblies separate within a single process
  • .NF - manages app domains. O.S - manages processes.
  • Create an App Domain - AppDomain d = AppDomain.CerateDomain("NewDomain");
  • Load Assembly into an App Domain -
  • 1) AppDomain d = AppDomain.CreateDomain("NewDomain");
  • 2) d.ExecuteAssembly("Assembly.exe");
  • Unload an App Domain - AppDomain.Unload(d); - individual assemblies cannt be unloaded.

Tuesday, 13 November 2007

Chapter 7, lesson 3: Asynchronous Programming Model (APM).

  • APM - allowing some portions of code to run on separate threadds.
  • Many classes support APM - supply BeginXXX and EndXXX. e.g. FileStreamBeginRead(), EndRead(). Allows asynch. execution of mthds.
  • EndXXX() - calling this blocks until asynch work is complete.
  • Rendevous Models - informs when to call EndXXX(). 3 models - Wait-Until-Done, polling, callback.
  • wait-until-done:
  • 1) strm.BeginRead(buffer,0,buffer.Length,null,null); - null for last 2 args as not Callback.
  • polling:
  • 1) while (!result.IsCompleted){//do work here Thread.Sleep(100);}
  • callback model:
  • 1) Create new AsyncCallback delegate (on another thread) when operation is complete - strmBeginRead(buffer,o,buffer.Length,new AsyncCallback(CompleteRead),strm);
  • ThreadPool - built-in, and can be used in many situations where might expect to to create own threads.
  • 1) WaitCallback workItem = new WaitCallback(WorkWithParameter);
  • 2) ThreadPool.QueueUserWorkItem()
  • ThreadPool - faster - threads reused + saves expensive setup costs. As threads become available, the thread pool posts new work to the thread.
  • change threa pool thread limits - 1) thread starvation, 2) startup thread speed.

Chapter 7, lesson 2: Sharing Data.

  • We can share data bet. multiple threads.
  • multithreading - multiple thredas might be interrogating our objs simult.
  • Interlocked.Increment - adds 1 to value as atomic operation.
  • Interlocked Class - only works with small number of .NET types.

Syncronization Locks

  • Synch locks - to allow one to synch. access to objects in .NET. Can synch access to your own classes + treat larger sections of code as atomic.
  • deadlocks - be careful!!

Other Synch. Mthds.

  • ReaderWriterLock class - lock access to readers and writers separately - allow mult. concurrent readers but only a sinlge writer.
  • To acquire a reader lock:
  • 1) Instance of ReaderWriterLock class - to be shared across any threads.
  • 2) try/catch block - catch ApplicationException - where acquisition of reader lock fails.
  • 3) acquire lock - ReaderWriterLock.AcquireReaderLock.
  • 4) try/finally - to hold any read code. thread-safe read in try, release lock in finally.
  • To acquire a wrtier lock - analogous.

  • Windows kernel objs - Mutex, Semaphore, Event.
  • Much slower than using Monitor.
  • When to use?:
  • 1) Mutex - allows synch. across AppDomain and process boudaries.
  • 2) Semaphore - throttles access to a resource to a set no. of threads.
  • 3) Event - provides a way to notify mult. threads - across AppDomain and process boundaries - that some event has occurred.

  • Mutex
  • 1) create instance of Mutex to be shared across any threads - Mutex m = new Mutex();
  • 2) WiatOne - to wait until lock is available.
  • 3) try/finally - try - do thread-safe work - finally - release lock.