This Blog Has A New Home!

This blog has been moved to www.SoftwareRockstar.com. Articles already here will remain intact, while new content will only be added to the new location at www.SoftwareRockstar.com.

Showing posts with label SQL Server. Show all posts
Showing posts with label SQL Server. Show all posts

Thursday, October 18, 2007

Astoria and Jasper: Old Ideas New Technology

SubSonic is an excellent open source DAL generation tool developed by Rob Conery that has been around for almost a year. In most cases SubSonic can just be added to your project, pointed to a databse, and you magically and immediately gain access to a rich and strongly typed object model that can be used to query and persist data to and from your relational data source. SubSonic also has a cool feature called the REST handler that essentially allows one to use HTTP protocol as an interface to data stored in a back-end relational database. It is URI based and returns data back in XML format. This data can then be used by decoupled client applications as they see fit. If you have never looked at SubSonic, you owe it to yourself to checkout this very cool tool. Recently Microsoft unveiled their plans to release similar features codenamed Astoria and Jasper with .NET framework 3.5 and Visual Studio 2008. The CTP of Astoria and Jasper are available for download from Microsoft. Jasper is described by Microsoft as:
Project Jasper is geared towards iterative and agile development. You can start interacting with the data in your database without having to create mapping files or define classes. You can build user interfaces by naming controls according to your model without worrying about binding code. Project Jasper is also extensible, allowing you to provide your own business logic and class model. Since Project Jasper is built on top of the ADO.NET Entity Framework, it supports rich queries and complex mapping.
Pablo Castro, the mastermind behind Astoria describes it as:
The goal of Microsoft Codename Astoria is to enable applications to expose data as a data service that can be consumed by web clients within a corporate network and across the internet. The data service is reachable over HTTP, and URIs are used to identify the various pieces of information available through the service. Interactions with the data service happens in terms of HTTP verbs such as GET, POST, PUT and DELETE, and the data exchanged in those interactions is represented in simple formats such as XML and JSON.

The Astoria web site also includes sample online services that showcases how this new technology can be used. It also allows anyone with a Passport account to design and host their own experimental data services .

Wednesday, April 18, 2007

SQL Server Database Comparison and Synchronization

Since database are usually designed in development environments, migrating changes over to other environments (e.g. QA and production) is not a trivial task.  This is because SQL Server does not have any built-in tools to compare database schemas. 

There are quite a few third-party tools that would make your life easier, most notably, Red Gate's SQL Compare (reasonably priced around $300).

At times, buying a commercial tool is not really an option, so one must resort to googling for free tools.  There are three such tools that I am aware of:

  1. SQLDBDiff by SQLDBTools
    A very decent tool that comes in both freeware and shareware versions.  Freeware version is not badly crippled; only advanced features such as multi-database comparison, data content comparison, etc. are disabled.

  2. Database Schema Comparison Utility
    This is a Code Project article that comes with C# source code of a schema comparison utility.  The utility itself is pretty bare-bone, but gets the job done.

  3. StarInix Free Database Compare 2.0
    I have not used this tool, but from the advertised feature list, it looks pretty good.  Most notably, in addition to SQL Server, this tool works with Access and MySQL databases.

Monday, February 05, 2007

SQL Server Locking Hints

While SQL Server provides automatic data locking mechanism which is good enough for most situations, there are times when developers must provide locking hints in their queries for better performance. There are several locking hints that can be used with SQL Server, however, the two most common ones are as follows: READ COMMITTED This is the default locking strategy used by SQL Server. PROS: Guarantees that only committed data is read. CONS: If a writer has a lock in place, readers are blocked until the writer releases it's lock, hence delaying readers. EXAMPLE

-- Default behavior; no special hint required
SELECT EmployeeID, EmployeeName FROM Employee

NOLOCK or READ UNCOMMITTED It is best used when approximations are acceptable, or for "dual-role" systems where database is responsible for many simultaneous reads and writes. PROS: Reads are blazing fast, since any exclusive locks are ignored. Also Shared Locks are not issued on rows read, so writers do not have to wait for read operations to complete. CONS: Data read may not be 100% accurate, since exclusive locks are ignored.

EXAMPLE

-- NOLOCK hint is used
SELECT EmployeeID, EmployeeName WITH (NOLOCK)
FROM Employee

Friday, August 18, 2006

Get Table Schema Programatically

In order to retreive table schema programatically, we can use the GetSchemaTable method of the DataReader as follows:

Thursday, August 17, 2006

Client Side Reports in Visual Studio 2005

Perhaps the best kept secret (or at least the least discussed feature) of Visual Studio 2005 is the client-side reports. Client-side reports consists of the Report Viewer Control and it's accompanying Report Designer that comes standard with Visual Studio 2005 Professional and up. This feature can be used to develop ASP.NET or WinForms solutions that sport SQL Server Reporting Services style reports, without having to deploy those reports to a Reporting Server. Reports are deployed as RDLC files with your solutions. In fact one doesn't even need SQL Server, since these reports can be programatically bound to objects such as DataSets, a huge plus for ditributed n-tier designs where the UI layer does not have direct access to the data store. This also means that one can use any imaginable back-end data store including XML and CSV files as long as data can be loaded into binable objects. The report viewer control is similar to Reporting Services report viewer, with nifty features such as paging, searching, and export (PDF, Excel, CSV) features. My only complain with the ASP.NET version of the report viewer is that it does not directly support printing. Reports have to be exported to PDF in order for one to print. This was a gotcha with the first versions of Reporting Services report viewer as well, but later they added printing support to the control (perhaps through ActiveX) in Reporting Services SP1. You can find more information about this feature at GotReportViewer.

Securing ASP.NET 2.0 Apps Using Membership and Role Providers

I recently designed an intranet application using ASP.NET 2.0 and really loved the membership and role providers that tremendously simplifified our implementation of security features in the application. Membership and role information can be stored in a SQL Server database or another repository such as Active Directory. For our intranet application it made sense to use Active Directory as the membership provider and SQL Server as the role provider.

Configuring Role and Membership Providers:

Essentially everything is configured declaritively using Web.config:

In the above configuration file, note that we first specify our connection strings starting at line 2. LocalSqlServer points to a SQL Server database which has been configured using aspnet_regsql. The second connection string points to the domain controller for membership authentication.

In the authentication section we specify that we are using forms authentication, and provide the URL for our logon page.

In the roleManager section we configure our role provider, pointing back to LocalSqlServer as the role repository.

In the membership section we configure our membership provider pointing back to ADConnectionString (domain controller) specified in the connectionStrings section.

Finally we restrict users from accessing certain folders based on their roles using location sections (role-based security).

Wednesday, August 16, 2006

Copy Virtual Machine With SQL Server Installed

I copied the VHD file of a virtual machine that had SQL Server 2000 installed on it. After running NEWSID from Sysinternals and giving my virtual machine a new name, I had to deal with the fact that SQL Server would not recognize my new machine name. Luckily I found this FAQ on Vyas’s web site that solved my problem. Essentially I had to drop and add my SQL Server as follows in order for things to start working correctly: Restart your SQL Server service. Connect using Query Analyzer and run the following command (It should output the new server name):

New Articles On Software Rockstar