ASP.NET SQL Server
Total Page:16
File Type:pdf, Size:1020Kb
CYAN YELLOW MAGENTA BLACK PANTONE 123 C BOOKS FOR PROFESSIONALS BY PROFESSIONALS® THE EXPERT’S VOICE® IN SQL SERVER Companion eBook Available Pro ASP.NET for SQL Server: High Performance Data Access for Web Developers Pro Dear Reader, ASP.NET ASP.NET As web developers, we work with ASP.NET and SQL Server by using a rich toolkit of databound controls and database functionality that promises great Pro performance and productivity gains after we know how to use it properly. Unfortunately, that toolkit is cluttered with a wide spectrum of features—some ideal for the one-man shop building a tiny application, and others aimed at large developer teams producing websites used by thousands of people. This book carves out a path for the senior developer who needs to produce a professional website that will perform well under high load. I focus on what a senior developer should know and use daily while also for explaining which features to avoid and why. There are several, little-known features ASP.NET in ASP.NET and SQL Server that work very well together without requiring much effort. These features get detailed coverage. Each chapter includes a full sample project, to help you learn by digging into some good code. These projects are for designed to keep you engaged while using them to understand the chapter topics in greater detail. What you will learn from this book are techniques that allow you to leverage SQL Server the many performance and productivity improvements that have been provided ASP.NET and SQL Server. These improvements will help you produce better SQL Server websites with the desired results right from the start. This book is meant to be a guide as well as a recipe book for you to use as you incorporate the techniques I discuss into your projects. The book also focuses on producing websites that will be easier to maintain and to adjust to meet changing needs as traffic to High Performance Data Access your websites increases. Having this book will be an asset to you in your daily work, as it guides you toward using ASP.NET and SQL Server more effectively. for Web Developers Brennan Stehling Companion eBook THE APRESS ROADMAP Mastering the bridge between ASP.NET and SQL Server Beginning ASP.NET 2.0 E-Commerce in C# 2005 See last page for details Pro ASP.NET 2.0 Pro ASP.NET on $10 eBook version Website Programming for SQL Server Beginning SQL Server 2005 for Developers Stehling SOURCE CODE ONLINE ISBN-13: 978-1-59059-860-3 www.apress.com ISBN-10: 1-59059-860-1 Brennan Stehling 5 5 9 9 9 US $59.99 Shelve in Microsoft/.NET www.free-ebooks-download.org User level: 9 781590 598603 Intermediate–Advanced this print for content only—size & color not accurate spine = 0.82" 432 page count www.free-ebooks-download.org 8601Ch00 8/28/07 4:33 PM Page i Pro ASP.NET for SQL Server High Performance Data Access for Web Developers Brennan Stehling 8601Ch00 8/28/07 4:33 PM Page ii Pro ASP.NET for SQL Server: High Performance Data Access for Web Developers Copyright © 2007 by Brennan Stehling All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 (pbk): 978-1-59059-860-3 ISBN-10 (pbk): 1-59059-860-1 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Lead Editors: Jonathan Gennick, Jim Huddleston Technical Reviewer: Vidya Vrat Agarwal Editorial Board: Steve Anglin, Ewan Buckingham, Gary Cornell, Jonathan Gennick, Jason Gilmore, Jonathan Hassell, Matthew Moodie, Jeffrey Pepper, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Project Manager: Kylie Johnston Copy Editors: Sharon Wilkey, Ami Knox Assistant Production Director: Kari Brooks-Copony Production Editor: Ellie Fountain Compositor: Diana Van Winkle, Van Winkle Design Proofreader: April Eddy Indexer: Carol Burbo Cover Designer: Kurt Krames Manufacturing Director: Tom Debolski Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail [email protected], or visit http://www.springeronline.com. For information on translations, please contact Apress directly at 2855 Telegraph Avenue, Suite 600, Berkeley, CA 94705. Phone 510-549-5930, fax 510-549-5939, e-mail [email protected], or visit http://www.apress.com. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this book is available to readers at http://www.apress.com in the Source Code/ Download section. 8601Ch00 8/28/07 4:33 PM Page iii Contents at a Glance About the Author . xi About the Technical Reviewer . xiii Acknowledgments . xv Introduction . xvii ■CHAPTER 1 Getting Started . 1 ■CHAPTER 2 Data Model Choices . 37 ■CHAPTER 3 Database Management . 55 ■CHAPTER 4 Databound Controls . 73 ■CHAPTER 5 SQL Providers . 111 ■CHAPTER 6 Caching . 147 ■CHAPTER 7 Manual Data Access Layer . 191 ■CHAPTER 8 Generated Data Access Layer . 233 ■CHAPTER 9 Deployment . 255 ■CHAPTER 10 A Sample Application . 289 ■APPENDIX Photo Album . 343 ■INDEX . 399 iii 8601Ch00 8/28/07 4:33 PM Page iv 8601Ch00 8/28/07 4:33 PM Page v Contents About the Author . xi About the Technical Reviewer . xiii Acknowledgments . xv Introduction . xvii ■CHAPTER 1 Getting Started . 1 Preparing Your Environment . 1 Project Organization . 2 Common Folders . 4 Datasource Configuration . 5 Code and Database Separation . 7 Managing Provider Services . 7 Using the Command Line . 8 Mixing and Matching Providers . 11 Configuring Providers . 11 Membership Configuration . 13 Roles Configuration . 14 Profile Configuration . 15 Creating Users and Roles . 18 Securing the Admin Section . 34 Creating the Admin User . 35 Summary . 36 ■CHAPTER 2 Data Model Choices . 37 The Data Access Application Block . 37 Data Access Code Snippets . 39 Sample Database . 46 Trivial Data Examples . 47 Nontrivial Data Examples . 49 Typed DataSet . 49 Nontyped DataSet . 51 DataReader . 53 v 8601Ch00 8/28/07 4:33 PM Page vi vi ■CONTENTS DataObject . 53 What’s the Downside? . 54 Summary . 54 ■CHAPTER 3 Database Management . 55 Using Database Projects . 55 Visual Studio . 56 SQL Server Management Studio . 57 Managing Stored Procedures . 57 Managing Indexes and Constraints . 62 Performance Considerations . 65 Stability Considerations . 70 Unit Tests for Data . ..