Tuesday, October 26, 2010

AZURE: Error: (400) Bad Request

Have you been playing with Azure storage, trying to create Blobs, Tables or Queue’s ??

Have you been getting any of the following errors:

[Azure Blob Storage]
Microsoft.WindowsAzure.StorageClient.CloudBlobClient ccb = account.CreateCloudBlobClient();
CloudBlob cb = ccb.GetBlobReference("myblob2871618");
cb.DeleteIfExists();

FAILS with: StorageClientExecption
"One of the request inputs is out of range."
"The remote server returned an error: (400) Bad Request."
Error code: BadRequest

[Azure Table Storage]
Microsoft.WindowsAzure.StorageClient.CloudTableClient cct = account.CreateCloudTableClient();
cct.DoesTableExist("MyTable");
"Exception of type 'Microsoft.WindowsAzure.StorageClient.StorageClientException' was thrown."
StatusCode: System.Net.HttpStatusCode.BadRequest

[Azure Queue Storage]
Microsoft.WindowsAzure.StorageClient.CloudQueueClient ccq = account.CreateCloudQueueClient();
CloudQueue cq = ccq.GetQueueReference("myqueue");
cq.Exists();

"One of the request inputs is out of range."
"The remote server returned an error: (400) Bad Request."
System.Net.HttpStatusCode.BadRequest

Well, the solution is as I found a little simpler than imagined.

When I created my Storage account online I created it with my standard Camel Case name. PaulStorage. On my connection string I had the name of the storage and my key.

So it looked like:

DefaultEndpointsProtocol=https;AccountName=PaulStorage;AccountKey=XYZ…..

When you try and open the connection for my Cloud Storage Account, and pass this in, it will work fine, when you try and do anything like the statements above you get the errors listed.

I knew that for other things like Queue’s in Azure you need to specify them in lowercase or they don’t work. I asked around and found that Azure was very fussy when it came to case. Even though I had specified the Storage account as Camel case I needed to pass it in as lower case to have it work:

DefaultEndpointsProtocol=https;AccountName=paulstorage;AccountKey=XYZ…..

Once I made this remarkable at the time, discovery.. Everything started working.

One thing to note is that development storage is a lot more forgiving and you don’t have to worry about any of this.

Development storages connection string is as simple as it gets:

UseDevelopmentStorage=true

Monday, October 25, 2010

Azure Queue Explorer

Having played a great deal with Queues in the past, the opportunity to expand the abilities of a real world solution to use the concept of Queues in the cloud as a great way of doing what Queues do best, hold onto something for someone later on to pick it up, in a managed and ordered fashion.

It seems Azure Queues do just that, and I was so happy that I made a tool that enabled me to manage my Queues:

View and Create Queues
Send and Receive Messages
Peek what messages I Have
Delete Messages from the Queue

I have made this publicly available for all to use and play with, along with the all important source code, it's no trade secret on how to use them, it's just nice to have something ready to go that does it for me.

Check out the link here: Azure Queue Explorer

Source code

Friday, October 1, 2010

BizTalk 2010 On MSDN

You can now download from MSDN the full suite of BizTalk 2010. It came up today.

BizTalk Server 2010 Branch Edition (x86 and x64) - DVD (English) 660 (MB)

BizTalk Server 2010 Developer Edition (x86 and x64) - (English) 552 (MB)

BizTalk Server 2010 Enterprise Edition (x86 and x64) - DVD (English) 965 (MB)

BizTalk Server 2010 RFID Enterprise (x86 and x64) - DVD (English) 81 (MB)

BizTalk Server 2010 Standard Edition (x86 and x64) - DVD (English) 965 (MB)

Host Integration Server 2010 Developer Edition (x86 and x64) - (English) 152 (MB)

Host Integration Server 2010 Enterprise Edition (x86 and x64) - CD (English) 321 (MB)

Interestingly the developer edition which is a smaller download, actually contains the same contents as the Enterprise Edition.

What you have to do in SQL Azure that you take for granted in SQL Server

I have been using the cloud quite extensively and have had to come up with strategies for many things to adapt them to the restrictions on the cloud. I'll be doing a few posts on this as I go.

The first of these was the database setup in SQL Azure.

You usually need to store your data somewhere, I’m not going to go into the merits of Table Storage or SQL Azure, and I’ll cover that separately as the choice comes with penalties each side and needs a whole post about that.

What I do want to cover is the differences in the SQL Script you need to have to setup your databases in the first place in SQL Azure. The first thing you notice is that it’s a lot of extra work, and you notice this pretty early on. Many of the statements you are used to in SQL Server don’t work, or are partially supported, or not supported at all.

Take for example a simple user, you get by default an super user with full rights to the database. This is great to set it all up, but I want my application to have only read access to my database, so I need a new user, NEVER run your application with the privileges of the super user.

I then need to create the user, so I do the click on the database/security/users and say create user, a nice script comes up:

-- =================================================
-- Create User as DBO template for SQL Azure Database
-- =================================================
-- For login , create a user in the database
CREATE USER
FOR LOGIN
WITH DEFAULT_SCHEMA =
GO

-- Add user to the database owner role
EXEC sp_addrolemember N'db_owner', N''
GO

The first thing about SQL azure is there are NO popup wizards to help you, it’s all script, however you should ideally not be using the admin console, I always use script. In SQL Server my script for this would look like so:
SET QUOTED_IDENTIFIER ON
SET ANSI_NULLS ON
SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
SET ANSI_WARNINGS OFF
SET XACT_ABORT ON


/*
*********************************************************************************************************
-- TAB SIZE 4
IDENT SIZE 4
---------------------------------------------------------------------------------------------------------
Purpose: Create a new SQL Server Login, assign a default database
and associates the Login with a database read permission


Notes: none.

Revision History:
----------------------------------------------------------------------------------------------------------
| Date | Changed By | Reference | Comments
----------------------------------------------------------------------------------------------------------
| 20100804 | Paul Somers | Create a new login with DB access | Initial release
***********************************************************************************************************
*/
USE master
GO

IF NOT EXISTS (SELECT * FROM syslogins WHERE [NAME] = N'NewReader')
BEGIN
CREATE LOGIN NewReader WITH PASSWORD=N'Password@2',
DEFAULT_DATABASE=GEO1,
DEFAULT_LANGUAGE=us_english,
CHECK_EXPIRATION=ON,
CHECK_POLICY=ON
END
USE GEO
GO
IF NOT EXISTS (SELECT * FROM sysusers WHERE [name] = N'NewReader')
BEGIN
CREATE USER NewReader FOR LOGIN NewReader
END
USE GEO
GO
EXEC sp_addrolemember N'db_datareader', N'NewReader'
GO

SET QUOTED_IDENTIFIER OFF
GO
SET XACT_ABORT OFF
GO
SET ANSI_NULLS ON
GO

The very next thing you notice about SQL Azure is that if you run this it will not work, whilst this works fine in SQL Server. You get all sorts of errors.

Take the simple, USE statement. USE master

Msg 40508, Level 16, State 1, Line 1
USE statement is not supported to switch between databases. Use a new connection to connect to a different Database.

You can’t use it… ? Between databases

Ok, so I need to connect to master run that bit and then run the master part script? Ok so we try that, and then discover that there are MANY parameters that are not allowed, well all of them to be precise.

IF NOT EXISTS (SELECT * FROM syslogins WHERE [NAME] = N'NewReader')
BEGIN
CREATE LOGIN NewReader WITH PASSWORD=N'Password@2'
--DEFAULT_DATABASE=GEO1,
--DEFAULT_LANGUAGE=us_english,
--CHECK_EXPIRATION=ON,
--CHECK_POLICY=ON
END

My traditional way of creating a user will NOT work, or will be extra cumbersome.
It even complains about this statement:

Msg 40530, Level 16, State 1, Line 3
The CREATE LOGIN statement must be the only statement in the batch.

It actually wants you to do a single line statement in the master database:

CREATE LOGIN NewReader WITH PASSWORD=N'Password@2'

That done, I have to switch over to the database I want to give the user permissions to so I run this:

CREATE USER [DataReader]
FOR LOGIN [DataReader]
WITH DEFAULT_SCHEMA = dbo
GO

EXEC sp_addrolemember 'db_datareader', 'DataReader'

To finish it off and make it more robust for repeated deployments I can use:
IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N'DataReader')
DROP USER [DataReader]
GO

So my final steps are:

Connection to master:
CREATE LOGIN NewReader WITH PASSWORD=N'Password@2'

Connection to my specified database where I want to give the user permsission:

IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N'DataReader')
DROP USER [DataReader]
GO
CREATE USER [DataReader]
FOR LOGIN [DataReader]
WITH DEFAULT_SCHEMA = dbo
GO
EXEC sp_addrolemember 'db_datareader', 'DataReader'

It’s a bit of an effort, however if you use a database project in VS you need to keep this in mind.

Monday, September 27, 2010

BizTalk 2010 Released

I noticed with not too much fan fare that BizTalk 2010 has finally been released, a few days earlier than expected, we were expecting end of this month, however we got it in on the 27th.

http://www.microsoft.com/biztalk/en/us/default.aspx

You can now download the Developer edition for free, there is no license required or cost involved with using the developer edition.

It works quite nicely with Visual Studio 2010, and comes complete with all the adapters required.


You can download the evaluation version here:
Evaluation Version

Or the Developer Version here: Developer Edition

You may not see it on MSDN as yet for

Sunday, June 13, 2010

BizTalk 2010 Beta Public Availability

You can now download the beta of BizTalk 2010 from the BizTalk site at Microsoft: www.microsoft.com/biztalk

Please have a look, I've been running it for a while now and it looks good thus far.

If you encounter any issues please contact me: paul@somers.com

Saturday, June 12, 2010

BizTalk Best Practices

I conduced some training recently on BizTalk, and we were covering topics around BizTalk Best practices.
I looked at what was avilable on the internet, and edited this, added my own flavour on this and put together a best practices for BizTalk, with naming standards.
This would apply to pretty much all versions of BizTalk right up to 2010.
Please download it here: [DOWNLOAD]

Wednesday, March 10, 2010

What’s New in BizTalk 2009 R2…

We have had BizTalk 2006 R2, and now we will soon have BizTalk 2009 R2, so don’t get confused… and BizTalk is far from being replaced it only gets better.

I’ve been looking at 2009 R2 recently, and I can tell you a few things about what’s coming, within reason, as most of this is still under wraps I can’t spill all of the beans.

As an obvious start, there is support for Windows 7 and windows 2008 r2, also support for Visual Studio 2010 as expected, from the previous release a platform shift is required...

The BizTalk Administration console has gone for a few enhancements, making it easier to use particularly in live production environments, where lots of things might be happening at once, adding to the cool things in 2009, when HAT went away and tracking was available from the administration console.

The BizTalk mapper has had a few enhancements, things you would have thought should have been there long ago, and there are still many improvements here that never made it out of the product group that would make life much nicer.

FTP you say, we have been asking for SFTP for a long time, I hear whispers that it might be in this release… along with a whole bunch of new FTP features, keep your mouth open for this one, it looks good to me.

There are some new features introduced, and some enhancements to existing features, not as many as I would have liked… These lie round EDI, there is a focus on making this better in each release as we saw in 2009. EDI is not dead, just as Cobol is not dead.

There are plans to deprecate some features, why you would want to do this? However there are plans, not major or drastic, and you will have to wait and see all of them.

The SOAP Adapter is on the cards for removal, replaced by the WCF-BasicHttp, there is some contention amongst the industry as this adapter still provides some features not found in WCF.

SQL Adapter, this has been coming for some time and nothing thats not expected with most adapters, the old SQL Adapter may go and be replaced by a WCF SQL Adapter.

What does this mean if you want to upgrade? You need to be aware of what’s going, and if you are using any of this, you need to adjust your solution to use the alternatives.

All in all it shows the continued investment in the product going forward.. It’s good news.

Thursday, February 25, 2010

BizTalk vNext features or WF/WCF vnext features?

Look at the next version of BizTalk 2009 R2, coming soon, and then think what else would I like to see...

Then understand that the team that wrote BizTalk is the same team that made WF and WCF.

I'd turn it around to say, look at WF and WCF where the bulk of the effort is. What would I like to see here, as post Dublin we finally have a product that works, with nice hosting and manageability. This is really the way to go. .

So ask what you would like to see more of in this stack. As it's still not 100% usable, and very clunky in areas here BizTalk is seamless.

I'd like to see a mapper that works for WCF endpoints. Defined for contracts, to map incoming formats into that of the contract.

This would involve identifying the incoming format first, like matching it to a different contract/schema, for the map, and then applying the transformation. Sounds a lot like a BizTalk port.

Then mapping inside of WF, to construct an outgoing message from a different incoming format.

WF is far tooo clunky for this...

You will see more ws-* wcf adapters, however the other features, like debug orch in vs, never going to happen. It's already there in wf so why put it in BizTalk....

I've been waiting for that new mapper I saw 3 years ago to appear in BizTalk, still no sign of it....

Wednesday, January 20, 2010

Where does Dublin, WF and WCF fit with BizTak going forward?

I previously spoke about where BizTalk and Dublin (Insert Name), WF and WCF all fit…. Well here is my view.

As far as where does Dublin fit here I can only touch on this, Dublin could host the workflow, much like BizTalk hosts the orchestration and the communication to end points. Dublin workflows could call BizTalk to kick off the back end communication and orchestration process, and get a result when they are done. In this way the workflow/human workflow can interact with back end systems, in a correctly architected manner, you can of course cut the corners here and call wcf services hosted, not a good idea, you could call back end oriented workflows that would be hosed in Dublin. WF can’t talk to SharePoint, and it perhaps can’t talk to many back end systems, whose functionality live in BizTalk. For example WF can’t send a fax.

There are a few fax adapters that can. WF can’t map a document from one format to the format that the end system is expecting; it has no concept of this. WCF can’t do this, and WF can’t do this. BizTalk will be here for few more years still.