Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User...

35
Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates www.upsizing.co.uk

Transcript of Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User...

Page 1: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Moving from Access Databases to a Visual Studio/SQL Server Solutions

Andrew CouchUK Access User Group

asc associateswww.upsizing.co.uk

Page 2: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Phases

Migrating the database design and data to SQL Server, re-linking Access application to SQL Server

Migrating queries to views and stored procedures, also re-packaging the SQL behind Forms and Reports to SQL Server if targeting to Visual Studio. Performance tuning or to make the next step.

Migrating the application to use web forms and report services with Visual Studio

Page 3: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Migrating the Database Design and Data

Page 4: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Preparing the Database Design

Access Design• Tables & Fields

• Add missing defaults for Boolean fields

• Avoid zero-length string anomaly

• Add timestamps (recommended)

• Add auditing fields (nice opportunity to add at this point)

• Decide on specific data type mappings; memos to VARCHAR(MAX) or TEXT, OLE Objects to VARBINARY(MAX) or IMAGE and setting decimals precision

• Relationships• Correct for cycles removing cascade operations from

relationships (www.upsizing.co.uk/Art6_Relationships.aspx)

Page 5: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Preparing the Database Design (2)

• Table validation rules (checks)• Translate Access expressions and functions

• Field validation rules (checks)• Translate Access expressions and functions

• Indexes• Reject inefficiencies, 20% rule• Check indexing on foreign key fields• Check for primary keys, add if absent• Map ‘unique indexes that ignore nulls’ to unique index

and trigger

Page 6: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Schema’s and Synonyms

Page 7: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Architecture : Schemas/Security

Schemas• Group together design objects

• Partioning designs

• Combining Access databases

• Synonyms required for ease of reference

Security• Database roles

• Grant permission on schemas

• Assign users to roles

• User database roles schemas

Page 8: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Preparing Data

Issues• Missing data in a required field, fix data or make field allow

nulls, no workaround beyond this• Violation of other checks (validation rules), avoid by adding

checks after data migrated, or fix the data, adding checks after migration gets around some of these issues

• Date range problem and invalid dates, fix the data, no work around

• Violation of R.I and deep seated corruption, difficult to generalise, migrate data, remove bad data then add relationships

Page 9: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Migration Sequence

Initial Migration• Migrate optimised and corrected structure

• Check and fix data

• Migrate data

• Add checks, triggers, indexing and relationships

Commissioning• Check and fix data

• Drop checks, triggers, indexing and relationships

• Empty data

• Migrate data

• Add checks, triggers, indexing and relationships

Page 10: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Skills : SQL Server a new world ?

A more important system ?• Dba’s, support, security and reviews of changes to

design• Production and development environments• More developers

Better control• Version Control• Comparing Development and Production• Script files to transfer change, GUI dangers in

production environments!

Page 11: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Skills : SQL Server a new world ? (2)

Other Issues• Backups• Server Tuning• Security

Access Application• Could stop here and retain the Access front-end• Tune SQL converting as required to SP’s, Views and

Pass Through• Or we can go on and do further bulk conversions• Do all your existing queries work? Do you need all your

existing queries ?

Page 12: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Migrating queries and re-packaging the SQL behind Forms and Reports

Page 13: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Screen Control Example

SELECT BigCustomers.Country, BigCustomers.*FROM BigCustomersWHERE (((BigCustomers.Country)=[Forms]![frmPrompt]![txtCountry]));

Page 14: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Parameter Table & View

CREATE TABLE tblParameters(SelectedCountry VARCHAR(15),SelectedDate DATETIME,SelectedRegion VARCHAR(15),UserName VARCHAR(128) DEFAULT suser_name())

CREATE VIEW vw_tblParametersASSELECT * FROM tblParametersWHERE UserName = suser_name()

Page 15: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Translated View

CREATE VIEW vw_ResultsSimpleASSELECT * FROM BigCustomersCROSS JOIN vw_tblParametersWHERE [Country] = [SelectedCountry]

SELECT BigCustomers.Country, BigCustomers.*FROM BigCustomersWHERE (((BigCustomers.Country)=[Forms]![frmPrompt]![txtCountry]));

Page 16: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Another Example; optional start

SELECT IIf(Not IsNull([Forms]![frmPrompt]![txtTheDate]),IIf([Forms]![frmPrompt]![txtTheDate]<[Date],1,0),1) AS Expr1, IIf(Not IsNull([Forms]![frmPrompt]![txtCountry]),IIf([Forms]![frmPrompt]![txtCountry]=[Country],1,0),1) AS Expr2, BigCustomers.*FROM BigCustomersWHERE (((IIf(Not IsNull([Forms]![frmPrompt]![txtTheDate]),IIf([Forms]![frmPrompt]![txtTheDate]<[Date],1,0),1))=1) AND ((IIf(Not IsNull([Forms]![frmPrompt]![txtCountry]),IIf([Forms]![frmPrompt]![txtCountry]=[Country],1,0),1))=1));

Page 17: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Making Parameters Optional

CREATE VIEW vw_ResultsASSELECT * FROM BigCustomersCROSS JOIN vw_tblParametersWHERE COALESCE ([Country], ' ') =

COALESCE ([SelectedCountry], [Country], ' ') AND COALESCE ([Date], ' 1/1/1900') >=

COALESCE ([SelectedDate], [Date], '1/1/1900')

Page 18: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Translating SQL

“We choose here to consider maximising translation of objects to SQL Server objects,

rather than embedding SQL in code”

Stored Procedures Views Access Support Library Custom UDF Translation Parameter Translation Form/Report Control and Record Source re-packaging

SQL

Page 19: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .
Page 20: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

INSERT, UPDATE, DELETE• Stored Procedure (need to use pass-through queries to call

these by name)

• Pass-Through Query; containing explicit SQL

SELECT, CROSSTAB• View (need to indicate unique fields to make these

updateable, where possible, can be linked just like tables)

• Stored Procedure (read-only, can not be linked need to use pass-through queries to call these)

• Pass-Through Query (read-only); containing explicit SQL

What Queries Translate To

Page 21: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

References Nested Queries (Calculations)

• Work out how many layers are going to be required, and then decide whether it would be better to generate a results table using selection criteria, upon which to base the calculations or work with the Nested Query.

• www.upsizing.co.uk/Art3_NestedQueries.aspx

Parameters Table (Parameters)• Isolate all the screen references and parameter statements

and use a table containing parameters to filter the SQL, Conversion of IIF statements to CASE statements and use of COALESCE functions for optional parameters.

• www.upsizing.co.uk/Art7_Controls.aspx

Page 22: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Migrating the Application

Page 23: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Access Application Objects

Menus, Toolbars and Navigation

Forms

Reports

Macros, Modules and Form/Report Module Code

Page 24: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Architecture : Web Forms a Strategy Simple bound controls and templates

Web site menu

Master Pages and style sheets

Further points to consider• Screen layouts and screen areas

• Searching and filtering data

Page 25: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Example Converted Form

Page 26: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Sitemap

Page 27: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Master pages and Content Areas

Page 28: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

CSS to Control Presentation

Page 29: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Searching and Filtering

Page 30: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Application Issues

“We are only considering the use of bound controls with custom templates here”

Inconsistent data in fields

• invalid drop-down box selections

• invalid radio button selections

Error handling

• error handling is a necessity

Page 31: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Application Issues (2)

Grid control when inserting data

Searching and filtering for data

Locking problems• No support for timestamps on bound controls

Security strategies• Internet• Integrated security• ASP. net security

Page 32: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Report Services

Easy security with groups

Forms to prompt

Launching using ReportViewer controls

Import Access reports into a Visual Studio Report Server project

Page 33: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Report Server

Page 34: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

Skills : Lost Count Now?

New technology areas• SQL Server• Visual Studio web forms and .net• Report Server• IIS

Challenges for newcomers• Security• Security• And security

Page 35: Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates .

MUST

Download a trial version from www.upsizing.co.uk

Site contains a number of technical articles, expanding on these topics

[email protected]