October05

Create new SQL Azure database as a copy

Did you know you can create a new SQL Azure database as a copy of an existing database?  Yes, you can.  There are some important limitations on how this works which I will cover below.  

Create the new database

-- create a new database as a copy
create database new_database as copy of original_database

In order to do this you must be logged in as the DBO of the original database.  See the NOTE in the article as well.  I think this is important difference for most database apps, the logins that are contained in the database must be updated.

Note After the cross-server copy process is complete, use the DBO login and the ALTER USER statement to map users in the new database to logins on the new SQL Azure server. For example: ALTER USER userName WITH LOGIN='loginName'. For more information, see ALTER USER (SQL Azure Database).

More...

August30

Red Gate Sql Azure Backup using Import Export Service

This is pretty cool news to me. Red Gate has a very good track record of supporting SQL Server products and technologies. Well, they just updated their SQL Backup product to a new beta SKU including SQL Azure Backup that is using the Import Export service built by the DAC team!

Red Gate SQL Azure Backup

This gives us a much better user experience than our own CLI tool, or even the soon to be released Azure Portal update.

Import Export Service?

The I/E Service is a Windows Azure based mid tier service that runs in each Microsoft Datacenter. The user submits jobs to the service, and it takes care of the long running operations.

iediag

More...

August22

SqlBulkCopy Dispose part 2

OK, fair point.  According to a friend I didn’t make my case very well in the previous post on SqlBulkCopy and Dispose.

As he stated, yes, you can put it in a using statement. And it does implement IDisposable explicitly.  Doesn’t that mean that everything is done?

using(SqlBulkCopy bcp = new SqlBulkCopy(connection, SqlBulkCopyOptions.Default))
{
// DO something
}

// OR YOU CAN DO THIS
SqlBulkCopy bcp = new SqlBulkCopy(connection, SqlBulkCopyOptions.Default);

((IDisposable)bcp).Dispose();

Internally the using seems to get converted to call to the virtual IDisposable.Dispose method according to the IL code I have looked at for the code above.

As an alternative, you could cast it to an IDisposable and call Dispose.  The class does have IDisposable, but only exposes Dispose explicitly (through the cast above).  This is a bad practice in my opinion because most developers won’t look for it.  They will try .Dispose through Intellisense.  If it doesn’t work they assume they don’t need to clean it up.

More...

August14

Pick A Park Walt Disney World WP7

Pick a Park is an application I wrote for my kids on a different phone platform.  We used it to help us decide what park we wanted to visit while driving to Walt Disney World.  We originally had a Disney pin that we could spin to decide, but it would always be forgotten at home.  Since we lived about an hour away from the parks it was pretty easy for us to go, but there was always the debate about which park to visit.

The application is a very simple way to choose from two or more of the Walt Disney World theme parks and get a random choice of which one you should visit.

Pick A Park is in the Windows Phone MarketplaceMainPageScreenShot

Windows Phone 7

This version is for Windows Phone 7.  Since I work at Microsoft I got a free phone right when they first launched.  This app was my initial way to help learn the programming model.  I wrote this over Thanksgiving weekend 2010,  but I was so embarrassed by the app that I never released it until summer 2011.

The reason I finally released it was a XapFest event I attended where another internal Microsoft employee said that he felt you should always release the app while you are still a little embarrassed, it will keep you humble and motivate you to improve it.

To date there have been hundreds of downloads for what I was pretty embarrassed about at the time.  I get a few hate mail, but I get a lot of people just asking for advice on what park they should visit when they only have 1 days in Orlando after a conference.  Overall it has been a great experience.

Mango Update is interesting

I have been toying with the app more and more as Windows Phone Mango has progressed through beta.  I wanted to initially include two modes, one for picking the park, but another for just exploring which park you might want to visit.  But I couldn’t figure out how to do the data filtration because there was no database on the phone.  Now with Mango there is an embedded database (SQL CE), so I wanted to revisit the problem.  First a little about the current version.

More...

August13

The next Windows Phone 7 - Mango

I am sure that most people who follow Windows Phone 7 already know all about Mango.  But if you are just sort of casually following what Microsoft is doing around the new phone platform you will have missed a lot of what is in this video.  Joe Belfiore (Corporate Vice President) does a demo of some of the highlights for Mango.

Go watch it directly on YouTube, it is a good video.

More...

July26

My Favorite Visual Studio 2010 Plugins

I have gotten asked quite a few times why my Visual Studio looks different, or has some additional feature than another developers. There is a large community of plugins for Visual Studio (quite a few are free). I just wanted to link to two of the most popular that I send to people.

More...

June21

SqlBulkCopy should implement IDisposable

Ran into this issue today and wanted to write it down for others to hopefully find and save them some time in the future.

IDisposable means you need to cleanup, or does it?

If you use the SqlBulkCopy class (from System.Data.SqlClient) you would think that the object does not need to be cleaned up because it does not implement implicitly IDisposable, but you would be wrong.  Take a look in your favorite .net de-compiler at the Close method.

public void Close()
{
if (this._insideRowsCopiedEvent)
{
throw SQL.InvalidOperationInsideEvent();
}
this.Dispose(true);
GC.SuppressFinalize(this);
}

Notice that call to this.Dispose.  It is private, you can’t actually call it.  

It does implement the method explicitly, but you need to cast it ((IDisposable)bcp).Dispose() to get at the method.

More...

May04

WCF Web API

I listened to a really good HansleMinutes yesterday about WCF. I was actually going to skip it, but the title said “This is not your fathers’ WCF”.

I am glad I listened because the conversation was mostly around new initiatives in WCF, specifically the WCF Web API. Glenn Block has an entire blog post on the topic WCF Web APIs, HTTP your way. That post does a great job giving the high level overview.

Visit the WCF Codeplex site for the complete code and early release bits.

What’s the Big Idea?

To me the big idea was that you can expose a WCF service endpoint over HTTP with only HTTP messages (very lightweight).

Imagine you have a heavy service with lots of contracts for your “serious” API work, but you need to expose something trivial as well (think a simple time service to ensure the service endpoint is up, and our clocks are close enough together). Normally you would probably switch to using asmx or a simple SOAP service for this service. But you don’t have to do that, you could use WCF.

The problem with WCF has always been the abstractions away from the transport (HTTP in most cases). This is fine for well designed systems with lots of layers. But when you want something quick, it can be a pain to build and deploy. And then what if you want to evolve it? Good luck with versioning. Using a simple HTTP service makes that story much easier.

Links

Visit the WCF Codeplex site for the latest details

March22

Using EF 4.1 Code First to support multiple database vendors

With the release of the Entity Framework 4.1 I was interested to see how well the code first aspect works with multiple database vendors.  Could you use the code first modeling to change the database through a connection string?  I thought it might be worth a quick sample app to find out.

Download the sample Project

About the sample databases

I have an identical database in both SQL CE 4 and VistaDB 4.1.  Since they both have ADO.Net providers for the Entity Framework I decided to use them for this test.  The databases must have identical schema for this to work, otherwise your code wouldn’t match the database.  The data in the databases is slightly different, this is from an RSS Reader app.

The schema is fairly simple, only two tables.  RssFeeds (list of feeds the user wants to get entries from), and RssEntries (the actual RSS entries from the feed).  The schema is simple enough to be used for demo, but has real world data that always makes a demo much nicer.

More...

March17

NoSQL links to more information

 

There has been a buzz and hype about the No SQL movement for quite some time.  There was the much publicized Netflix using No Sql, which turns out to be a lot more about reaching internet scale rather than a discussion about relational databases.  In most of the cases where I see people hyping replacement of relational databases they are usually really talking about relaxing ACID compliance, eventual consistency of writes, or caching.

NOSQL Site Link

I recently got a link to an interesting site from a colleague and wanted to share it.

NoSql Summer

Specific Points

There is a lot of good information on the site, but here are a few I wanted to point out.

Cassandra — A Decentralized Structured Storage System – Interesting on a number of levels about scale and failover.

On Designing and Deploying Internet-Scale Services  - A lot of the scalability of any solution comes around a proper design for the scenario.  Why enforce a complete relational validation on something that is temporary for a service?  There are lots of reasons when you should not use a database at all for a problem.

Eventually Consistent – This is perhaps one of the best topics (to me).  There are lots of scenarios where you know your data is cached on a mid tier, and you really only want to make sure the persisted data is eventually consistent.  Perhaps you are always going to read from some cache unless it is empty, then you go back to disk.

The Log-Structured Merge-Tree (LSM-Tree) – Ok, this is just for us computer science geeks…  But it is a really cool concept.  Anyone who has implemented a B-Tree and had to deal with merge operations in a multi threaded scenario will appreciate the thought in this paper.  Not for the neophyte.

If you are at all interested in these topics jump to the site and read through the complete list of papers.