Content by Category
.NET 1.x
.NET 2.0
.NET 3.0
.NET 3.5
.NET 4.0
.NET 4.5
.NET Assemblies
.NET Framework
.NET Getting Started
Accessibility
ADO.NET
Advertorials
Agile Development
AJAX
Amazon Web Services
Analysis Services
Android
Architecture
Arduino
ASP .NET Web API
ASP.NET
ASP.NET MVC
ASP.NET WebForms
Azure
B2B (Business Integration)
BDD
Big Data
Bing
BizTalk
Book Excerpts
Build and Deploy
Business Intelligence
C#
C++
ClickOnce
Cloud Computing
Code Contracts
CODE Framework Info - non Technical
CODE on the Road!
COM+
Community
Conferences
Continuous Integration
Crystal Reports
CSLA.NET
CSS
Data
Debugger
Design Patterns
Development Process
Display Technologies
Distributed Computing
Document Database
DotNetNuke
DSL
Dynamic Languages
Dynamic Programming
Editorials
Enterprise Services ("COM+")
Entity Framework
Events
Expression Blend
F#
Fox to Fox
Frameworks
Functional Programming
Git
Graphics
HTML 5
Internet Explorer 8.0
Interviews
IOS
iPhone
Iron Ruby
Java
Java Script
JavaScript
jQuery
JSON
Lightswitch
LINQ
Linux
LUA
Mac OS X
MDX
Messaging
Metro
Microsoft Application Blocks
Microsoft Business Rules Framework
Microsoft Dynamics
Microsoft Expression
Microsoft Office
Mobile Development
Mobile PC
Mono
MsBuild
MVVM
MySQL
Network
NHibernate
node.js
NOSQL
Nuget
Object Oriented Development
Objective C
Odata
OLAP
Open Source
Opinion
Opinions
Oracle
ORM
Other Languages
Parallel Programming
Patterns
PHP
Podcasts
Post Mortem
PowerPoint
Print/Output
Prism
Product News
Product Reviews
Project Management
Prolog
Python
Q&A
Rails
Rake
Razor
Reporting Services
REST
RIA Services
Ruby
Ruby on Rails
Scheme
Search
Security
Services
SharePoint
SignalR
Silverlight
SOA
Social Networks
Software & Law
Software Business
Source Control
Speech-Enabled Applications
SQL Server
SQL Server 2000
SQL Server 2005
SQL Server 2008
SQL Server 2012
SQL Server CE/AnyWhere/Mobile/Compact
SSIS
Subversion
Sync Framework
Tablet PC
TDD
Team System
Techniques
Testing and Quality Control
TFS
Tips
TypeScript
UI Design
UML
User Groups
VB Script
VB.NET
Version Control
VFP and .NET
VFP and SQL Server
Virtual Earth
Vista
Visual Basic
Visual Basic 6 (and older)
Visual FoxPro
Visual Studio .NET
Visual Studio 11
Visual Studio 2005
Visual Studio 2008
Visual Studio 2010
Visual Studio 2011
Visual Studio 2012
Visual Studio Tools for Office
VSX
WCF
Web Development (general)
Web Services
WebMatrix
WF
Whitepapers
Windows 7
Windows 8
Windows Azure
Windows Live
Windows Phone 7
Windows Phone SDK
Windows Server
Windows Vista
WinForms
WinRT
Workflow
WPF
XAML
Xiine Documentation
XML
XNA
XSLT



LearnNow


XAMALOT
 


LearnNow

Reader rating:
Click here to read 1 comment about this article.
Article source: CoDe (2007 - Vol. 4 - Issue 3 - Data Programability )


Article Pages:  1  2 3 - Next >


Programming SQL Server 2008

SQL Server Katmai, now officially announced as SQL Server 2008, introduces a significant amount of new and improved functionality, including enhanced data types and greater programming flexibility for database application developers.

In this article I’ll look at the range of data access technologies available for leveraging the power of SQL Server 2008. After I show you how to select the right technology for your needs, I’ll dive into the improvements, first examining a new construct for programming data. Then I’ll turn to expanding the set of building blocks-data types-available to developers. Taking a brief pause, I’ll discuss how SQL Server 2008 removes limitations for some scenarios. Then building on what the article has covered, I’ll examine new out-of-the-box solutions for common application scenarios. The article will hopefully leave you with a new understanding of the possibilities for taking advantage of Katmai: SQL Server 2008.

Choosing a Data Access Technology

SQL Server offers a wide range of data access technologies to developers. The best place to start the discussion on taking advantage of new programmability features is how to choose the right one. For new application development, using the .NET Framework and specifically the SQL Server provider in ADO.NET, System.Data.SqlClient, will be the best choice in most cases. If you’re working within an existing application with business logic and associated data access code in native C/C++, you can choose from the SQL Server Native Client ODBC driver or the OLE DB provider. Both options allow you to take advantage of the full set of features of SQL Server 2008 and the choice will usually be based on your application requirements.

Additional data access options include Windows Data Access Components (WDAC)-new in Windows Vista, previously named Microsoft Data Access Components (MDAC)-and the Microsoft SQL Server 2005 JDBC Driver for Java environments. For purposes of this discussion, I’ll focus on SqlClient and SQL Server Native Client; for more information on these and other data access technologies, visit http://msdn.com/data.

To get the most out of the new functionality, you’ll need to use .NET Framework 3.5 or SQL Server Native Client 10.0 which works side-by-side with previous versions. One important takeaway is that you don’t have to rewrite your application from the ground up to take advantage of SQL Server 2008. Instead, you can gain significant value from incremental changes to your existing data access layer. With that said, let’s dive in.

New Programming Constructs: Table-Valued Parameters

One of the most requested new features by developers is the ability to cleanly encapsulate tabular data in a client application, ship it to the server in a single command, and then continue to operate on the data as a table in T-SQL. The simplest such use case is the long-desired array data type. Traditionally, applications solve this need by doing one of the following:

  • Defining stored procedures with large numbers of parameters and pivoting the scalar parameter data into rows.
  • Using an out-of-band bulk insert mechanism like SqlBulkCopy in ADO.NET to create a temporary table.
  • Using parameter arrays in the application and repeatedly executing logic that operates on a scalar “row” of data.

None of these solutions is ideal. The pivoted parameter solution, in addition to being ungraceful, creates code that is difficult to maintain that’s also tough to move forward when the time comes to add a new “column” to the conceptual “table.” The bulk insert solution is clumsy when the application needs to do any additional filtering or apply more complex logic. The parameter array solution, while it may perform well for small data volumes, becomes untenable for larger batches both on the client where memory consumption may become a problem and on the server where per-row invocations of the procedure provide non-optimal performance.

Table-valued parameters (TVPs), believe it or not, address all of these problems. TVPs provide an improved programming model and significant performance benefits in certain scenarios.

Imagine a simple order processing scenario. Using TVP starts with defining a table type in T-SQL on the server:

-- TSQL to CREATE a TABLE TYPE tt_OrderItems

CREATE TYPE tt_OrderItems AS TABLE (
  [ItemId]      int     NOT NULL,
  [Quantity]    int     NOT NULL)

Next, create a stored procedure that uses the table type you just created and additionally takes the customer who placed the order as a parameter:

-- TSQL to CREATE a PROCEDURE sp_AcceptOrder 
-- that performs set-based operation on TVP

CREATE PROCEDURE sp_AcceptOrder (
  @CustomerId     int,
  @OrderItems     tt_OrderItems READONLY)
AS
INSERT dbo.AcceptedOrders
    SELECT O.ItemId, O.Quantity 
    FROM @OrderItems AS O
       INNER JOIN dbo.Items AS I
       ON O.ItemId = I.ItemId
    WHERE I.BackOrdered = 0

This example is fairly simple, but it illustrates a big win for developers, which is that if you can update an application to implement its business logic to use set-based operations on a batch of data, it should see significant performance gains.

Here are the application changes needed to use table-valued parameters. When using table-valued parameters, client applications generally have two possible programming models:

  • Bind in-memory table data as a parameter. This is usually the simplest and fastest to code at the expense of not being as scalable in the application for large batches of data due to increased memory consumption.
  • Stream row data to the provider from a disk or network-backed data source. This model takes a bit more code to set up with the advantage of having a fixed memory usage profile in the application.

For small batches of data, the performance difference on the client will usually be negligible, so choosing the simpler programming model may be your best choice. On the server side there will be no performance difference between the models.

Diving into the details for a moment, ADO.NET accomplishes the first model by extending the SqlParameter class to take a DataTable as a value. DataTable’s ubiquity in data application programming makes it an ideal choice for this simple model. SQL Server Native Client OLE DB accomplishes the same model by leveraging the COM IRowset interface and by introducing an implementation that allows buffering. SQL Server Native Client ODBC uses a similar method modeled after parameter arrays where applications allocate and bind arrays of buffers. For the streaming model, ADO.NET supports specifying DbDataReader and IEnumerable<SqlDataRecord> as a parameter value, which provides a solution for both external and user-defined data sources. In much the same vein, SNAC OLE DB accepts a custom IRowset implementation and ODBC builds on the data-at-execution (DAE) paradigm by accepting DAE table-valued parameters. All providers also expose a rich set of services for discovering and describing table-valued parameter metadata.

"
When you can update an application to use table-valued parameters, it should gain the benefits of having cleaner, more maintainable code in both the client and server application tiers; faster performance, particularly when you use set-based operations on the server side by leveraging the power of the SQL query processor; and better scalability for large data volumes.
"

When you can update an application to use table-valued parameters, it should gain the benefits of having cleaner, more maintainable code in both the client and server application tiers; faster performance, particularly when you use set-based operations on the server side by leveraging the power of the SQL query processor; and better scalability for large data volumes. In addition to enhancing the programming model, SQL Server 2008 introduces new intrinsic data types to better align with the precise needs of applications.

&

By: Vaughn Washington

Vaughn Washington currently leads the development team for native data access in the SQL Server division at Microsoft; Vaughn is responsible for building and maintaining Microsoft’s world class data providers for SQL Server: ODBC and OLE DB. His responsibilities include delivering scalable, performant, and secure client components that are consumed by Microsoft internal and external customers through APIs that adhere to industry standards and expectations while showcasing SQL Server’s unique value proposition.

vaughn.washington@microsoft.com

Fast Facts

Did you know SQL Server 2008 has already released more than 16 improvements in the July CTP? You can register to participate in this and future technology previews at: http://connect. microsoft.com/sql



Article Pages:  1  2 3 - Next Page: 'New Building Blocks: New and Enhanced Date and Time Types' >>

Page 1: Programming SQL Server 2008
Page 2: New Building Blocks: New and Enhanced Date and Time Types
Page 3: Breaking Barriers: Removing Size Limitations

How would you rate the quality of this article?
1 2 3 4 5
Poor      Outstanding

Tell us why you rated the content this way. (optional)

Average rating:
3.3 out of 5

13 people have rated this article.

Instantly Search Terabytes Of Text
“Lightning Fast”
– Redmond Mag
“Covers all data
sources” – eWeek
25+ fielded & full-text search options
dtSearch’s own document filters highlight hits in popular file types
Web Spider supports static & dynamic data
APIs for .NET, Java, C++, SQL, etc.
Win / Linux (64-bit & 32-bit)
www.dtSearch.com
 

      CODE Training

 

LearnNow