Friday, December 25, 2009

WCF Data Services

Project Astoria == ADO.NET Data Services == WCF Data Services

As announced at PDC this afternoon by Pablo, the ADO.NET Data Services framework is being renamed WCF Data Services as the first part of a long term effort to align all the Microsoft technologies for building n-tier applications and services. 

While this change does not affect current product plans or deliverables for Dev 10 or Silverlight, it is the first key step in simplifying our offerings in this space.

Thursday, December 24, 2009

Microsoft Banned From Selling Word From 11th January 2010

Microsoft [MSFT], yesterday lost its appeal in a Federal Court, in the patent case brought against Microsoft by i41 Ltd of Canada, regarding the use of their XML related patents what were used in Microsoft Word 2007.

From the 11th of January 2010, Microsoft will have to stop selling Microsoft Word, which basically means Microsoft office, unless they agree some out of court settlement with i4i before that date.

Microsoft Banned From Selling Word From 11th January 2009

This injunction applies only to copies of Microsoft Word 2007 and Microsoft Office 2007 sold in the U.S. on or after the injunction date of January 11, 2010.  Copies of these products sold before this date are not affected.

With respect to Microsoft Word 2007 and Microsoft Office 2007, we have been preparing for this possibility since the District Court issued its injunction in August 2009 and have put the wheels in motion to remove this little-used feature from these products. Therefore, we expect to have copies of Microsoft Word 2007 and Office 2007, with this feature removed, available for U.S. sale and distribution by the injunction date.

It will be interesting to see if Microsoft manages to reach an agreement with i4i Ltd, or if they just remove the code from Microsoft Word as they have stated in their press release.

Monday, December 14, 2009

TextDecoration Class

In .Net Framework 3.0. There is one new class is introduced named Text Decoration under the name space System.Windows.

A TextDecoration object is a visual ornamentation you can add to text

There are four types of text decorations: underline, baseline, strikethrough, and overline. The following example shows the locations of the text decorations relative to the text.

Example of text decoration types

Diagram of text decoration locations

The following example shows a text decoration that has been styled with a linear gradient brush and a dashed pen.

Example of an underline styled with a linear gradient brush and dashed pen

Text decoration with linear gradient underline


Visit more here about Text Decoration class…..

Tuesday, December 08, 2009

Visual Studio 2008 SP1: LINQ to SQL and FILESTREAM

LINQ to SQL and FILESTREAM In Visual Studio 2008 and .Net Framework 3.5 SP1, not only that LINQ to SQL supports the new date and time types of SQL Server 2008, but is also supports forking with FILESTREAMs.

Using the File Management Schema from my SQL Server 2008 FILESTREAM post, I created a simple .net application that uses LINQ to SQL in order to access the file contents.

Just a reminder of how the Files table looks like:

CREATE TABLE [dbo].[Files]


    FileID uniqueidentifier NOT NULL ROWGUIDCOL PRIMARY KEY,

    FileContents varbinary(max) FILESTREAM DEFAULT(0x)


and the corresponding LINQ to SQL model and generated code look like:


imagepublic partial class File


  private System.Guid _FileID;

  private System.Data.Linq.Binary _FileContents;


          DbType="UniqueIdentifier NOT NULL",

  public System.Guid FileID


    get { ... }

    set { ... }



  public System.Data.Linq.Binary FileContents


    get { ... }

    set { ... }



Notice that the FileContents field is defined as System.Data.Linq.Binary.

Reading a File Content

FileManagementDataContext db = new FileManagementDataContext();

var query = db.Files;

foreach (var file in query)


    byte[] buffer = file.FileContents.ToArray();

    System.IO.File.WriteAllBytes(file.FileID + ".txt", buffer);


In the above code block I create a new instance of the data context and query for all the files. Going over the files, I take out the file contents as a byte array from the System.Data.Linq.Binary field and write it to another file in the file system.

Adding a new File

byte[] inputBuffer = System.IO.File.ReadAllBytes("TextFile1.txt");

File newFile = new File();

newFile.FileID = Guid.NewGuid();

newFile.FileContents = new System.Data.Linq.Binary(inputBuffer);



In the above code I read all the contents of a file and get it as a byte array. Then, I create a new File object, assign a new ID and create a new instance of System.Data.Linq.Binary and pass the contents. Then, I use standard LINQ to SQL methods to add the file into the table and submit the changes to the database.


LINQ to SQL adds the support of using SQL Server 2008 FILESTREAM in Visual Studio 2008 and .Net Framework 3.5 SP1. The FILESTREAM columns is represented as a System.Data.Linq.Binary field that we can access it and get the file contents as a byte array.


Monday, December 07, 2009

SQL Server 2008 FILESTREAM - Part 1

SQL Server 2008 FILESTREAM SQL Server 2008 has a lot of new cool features that I've talked about before:


One of the great features in SQL 2008 is it's FILESTEAM support. To make things short, we can now not only store the path to the file in our database, but we can now store the whole file inside the SQL Server and than backup, restore and manage it just as we would do with any other data.

In this post series I will build a file management database with SQL 2008 FILESREAM and build a .net client application that works with it.

1. Enable FILESTREAM support

To enable FILESTREAM support, run the following sql command

exec [sp_filestream_configure] @enable_level = 3;

This command enables or disables the support according to the parameter. The value 3 means that FILESTREAM will be enabled for Transact-SQL, local file system access, and remote file system access.

You can find more details about sp_filestream_configure here.

2. Create a database with a File Group that contains FILESTREAM

To create a database instance with a file group that contains FILESTREAM, run the following sql command. This creates the database with 3 file groups, but only one of them contains FILESTREAM as you can see in the command.




    NAME = FileManagement_Primary,

    FILENAME = 'c:\temp\data\FileManagement.mdf'),


    NAME = FileManagement_FileGroup,

    FILENAME = 'c:\temp\data\FileManagement')

LOG ON ( NAME = FileManagement_Log,

    FILENAME = 'c:\temp\data\FileManagementLog.ldf')


This command will create the following directories structure:


In the Data Directory, I could find the files specified above:


and in the FileManagement directory, I could find the following content:


3. Create a Table with FILESTREAM

Note: FILESTREAM is not a type of a column, but it is a property you put on a varbinary(max) column.

So, in order to create a table with a varbinary(max) column that will be used for FILESTREAM, run the following command. Note that I don't have any additional columns to the file itself.

CREATE TABLE [dbo].[Files]


    FileID uniqueidentifier NOT NULL ROWGUIDCOL PRIMARY KEY,

    FileContents varbinary(max) FILESTREAM DEFAULT NULL


4. Add Test Data

In order to get the feeling of the experience of working with files, let add an empty file:

insert into Files

values (newid(), null);

If we now query the database to see the files in it:

select * from Files

we will get the following result (the GUID will probably be different...)

FileID                               FileContents

------------------------------------ ------------------------------------------------------------------


and If we look at the FileManagement directory, we can see that a new directory has been created


If we add a file with some content:

insert into Files

values (newid(), CAST ('my test file' as varbinary(max)));

we can query for it and see:

FileID                               FileContents

------------------------------------ ------------------------------------------------------------------


3C028D84-BA68-4E7B-8E87-B9889900D728 0x6D7920746573742066696C65

Since this hexadecimal content doesn't mean anything to use, and the fact that File is a type in SQL, we can query for some additional data such as path name:

select FileID, FileContents.PathName() as Path from Files

and get the following result:

FileID                               Path

------------------------------------ ------------------------------------------------------------------

8247CE78-74DF-4BDE-A08D-9760AE0B1555 NULL

3C028D84-BA68-4E7B-8E87-B9889900D728 \\GUYBUR-PC1\SQLEXPRESS\v1\ 


In this post I showed how to create an SQL Server 2008 database with FILESTREAM support and add some text data into it. In the next post I will show how to write a .net client application that works with this database to add and change files.


FILESTREAM Data in SQL Server 2008 (ADO.NET)

SQL Server 2008 introduces the FILESTREAM storage attribute for binary (BLOB) data stored in a varbinary (max) column.

SQL Server 2008 introduces two new capabilities for storing BLOB data:

  • FILESTREAM: An attribute you can set on a varbinary column so that the data is stored on the file system (and therefore benefits from its fast streaming capabilities and storage capabilities) but is managed and accessed directly within the context of the database.

  • Remote BLOB Storage (RBS): A client-side application programming interface (API) that is designed to move storage of BLOBs from Microsoft SQL Server to external storage solutions.

See the Video ‘How Do I: Use the Filestream Data Type to Store BLOB Data’

See the links about the File Stream on MSDN,

FILESTREAM Storage in SQL Server 2008

FILESTREAM Data in SQL Server 2008 (ADO.NET)

Visual Studio 2008 SP1: LINQ to SQL with SQL Server 2008 Date Time Types

One of the pillars of Visual Studio 2008 and .Net Framework 3.5 Service Pack 1 is the support for SQL Server 2008 in Visual Studio 2008 tools and the related data access technologies. I decided to check out how LINQ to SQL works with SQL Server 2008 Date and Time types in Visual Studio 2008 and .Net Framework 3.5 Beta.

I created a simple database with a single table called friends, that holds my friends names and birth dates in several formats according the existing and new types.

create table Friends


    FriendID int identity(1,1) not null primary key,

    [Name] nvarchar(50) not null,

    BirthDate date,

    BirthTime time,

    BirthDateTime datetime,

    BirthDateTime2 datetime2,

    BirthSmallDateTime smalldatetime,

    BirthDateTimeOffset datetimeoffset



When I dragged the Friends table from the Server Explorer to the OR/M Designer, I got a visual representation of the Friend class, with types corresponding to the table columns. This is the columns types mapping:image

Column Server Data Type CLR Type
BirthDate Date System.DateTime
BirthTime Time System.TimeSpan
BirthDateTime DateTime System.DateTime
BirthDateTime2 DateTime2 System.DateTime
BirthSmallDateTime SmallDateTime System.DateTime
BirthDateTimeOffset DateTimeOffset System.DateTimeOffset


Working with this class was just as usual as with any other type, both for querying and for updating. The result was a GridView full with details of this table:


Saturday, December 05, 2009

SQL Server 2008 T-SQL: Insert Multiple Rows


SQL Server 2008 T-SQL Insert Multiple

In SQL Server 2005, in order to insert 3 rows to a table, you had to run 3 INSERT statements:

insert into Customers (Name, City, Phone) values ('Customer #1', 'Jerusalem', '2343245')

insert into Customers (Name, City, Phone) values ('Customer #2', 'Tel Aviv', '0987345')

insert into Customers (Name, City, Phone) values ('Customer #3', 'Haifa', '275466')

In SQL Server 2008, you can insert multiple rows in a single insert statement that takes  a number of value arrays:

insert into Customers (Name, City, Phone)


    ('Customer #1', 'Jerusalem', '2343245'),

    ('Customer #2', 'Tel Aviv', '0987345'),

    ('Customer #3', 'Haifa', '275466')

Also nice...

SQL Server 2008 T-SQL: DECLARE and SET in the Same Statement


In SQL Server 2005, if you wanted to declare a new variable and set its value, you had to write both DELCARE and SET statements:


SET @City = 'London'

A new T-SQL improvement in SQL Server 2008 is allows you to write DECLARE and SET in the Same Statement:

DECLARE @City VARCHAR(20) = 'London'

If you try this in SQL Server 2005, you'll get the following error message:

Msg 139, Level 15, State 1, Line 0
Cannot assign a default value to a local variable.

Not a big deal, but can get our code to look better!


Friday, December 04, 2009

SQL Server 2008 IntelliSense

SQL Server 2008 IntelliSense

SQL Server 2008 IntelliSence

The most trivial feature in all developer tools is Intelligence. Developers just can't live without it, and when they do, they make mistakes that cause errors at runtime.

SQL Server 2008 now supports IntelliSense that can make developers more productive while writing database applications.

For example:

when writing queries against the DB:

SQL Server 2008 IntelliSense

or when writing a script, the editor notices that the Customers table has a column called Name, but does not have a column called Citu.

SQL Server 2008 IntelliSense

Great, isn't it?

BigInteger in .NET 4.0

One of the simplest new additions to the .NET 4.0 framework is an integer with arbitrary length, System.Numerics.BigInteger. Here’s a simple usage example, comparing it to a double:

DEFINATION :  The BigInteger type is an immutable type that represents an arbitrarily large integer whose value in theory has no upper or lower bounds.

WARNING : Because the BigInteger type is immutable (see Mutability and the BigInteger Structure) and because it has no upper or lower bounds, anOutOfMemoryException can be thrown for any operation that causes a BigInteger value to grow too large.

BigInteger b = BigInteger.Pow(2, 64);

Console.WriteLine("BigInteger: {0}", b.ToString("N"));

Console.WriteLine("Double:     {0}", Math.Pow(2, 64).ToString("N"));


b = BigInteger.Pow(2, 128);

Console.WriteLine("BigInteger: {0}", b.ToString("N"));

Console.WriteLine("Double:     {0}", ((double)b).ToString("N"));

The output is:


.NET 4, VS 2010 and Office: New Features in .NET 4 for Office Developers


Now that .NET 4 and VS 2010 are out, at least in Beta, I thought it would be a good time to show off some of the new features that are applicable to Office development.  In this first screen cast I will cover something new to C# specifically, optional parameters, as well as Lambda expressions. 

See the Video on the channel 9 here.