Showing posts with label SQL Data Services. Show all posts
Showing posts with label SQL Data Services. Show all posts

Thursday, March 12, 2009

Forget what I said about SQL Data Services :(

Remember my two posts about Microsoft Sql Data Services (Starting Up With SDS and Writing Data To The Cloud)?, well, they are both wrong now. Not wrong but old.

This week I read on the SDS blog that they will introduce relational data base features (which I think it’s great) but also that they are removing the good old ACE model.

Read the original post here

Edit: I just read a new post from the SDS team were they answered a few questions from developers.

This is what I asked them and what they answered:

You say, you will no longer support the ACE model since Windows Azure has the same data model. If I’m going to put my application in Windows Azure (as I did) my best option for data is SDS, right? As I understood, Microsoft’s approach for cloud computing was Windows Azure as the platform for developers and SDS to store the data. And now you say I can use Windows Azure storage… what’s the difference? What’s the path to follow?

The best storage option for an Azure Services Platform application depends on your application. At a very high level, if you require the features of a relational database, use SDS. If you require basic blob or “schemaless” storage, then Windows Azure Storage is for you. Both will be key capabilities available to developers in the overall Azure Services platform.

Read the whole Q&A session here.

Read Full Post

Thursday, January 15, 2009

Writing data to the cloud (SQL Data Services)

In a previous post I talked about setting up the environment for SQL Data Services. Now I’ll show you something I’ve done with it and hopefully it will help somebody thru.

I’ll use my Goomez project cause that’s like my sand box and also, and since it’s available online, you could download it and also play with it. I used the SQL Data Service to store and query the information, so instead of using Lucene.net I used SDS for this implementation, which I believe it’s a good scenario for SDS. That said, the changes you’ll see here were not committed to the svn repository.

But let’s get down to business. SDS has two interfaces, one is through web services, which implies importing the wsdl like any other web service which, if you do it with Visual Studio, it will create all the necessary proxy classes. The other way is REST and since I hadn’t tried anything with it before I thought it’d be a good idea to give that a try too (I must say it’s not a recommended practice, since if you crewed up, it’d be harder to know where).

One thing that I found missing is a good old REST API for .net. I don’t know if this is planed to stay like this, but it’s pretty crapy. You have to create a HttpWebRequest, HttpWebResponse and so forth… not something I enjoy doing. It was fun though (just for this time).

So, here’s the code of the function that actually saves the info of one of the indexed files (FileInfo) to the cloud.

Firts of all, create the request and response objects and set a few properties to the request

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(m_url);
HttpWebResponse response = null;
MemoryStream stm = null;

request.Credentials = new NetworkCredential("<YourSolution>", "<Password>");
request.Method = "POST";
request.ContentType = "application/x-ssds+xml";


In my example, m_url has the value https://goomez.data.database.windows.net/v1/goomezindex because goomez is the authority I created and goomezindex is the container. So now, the entities.



StringBuilder builder = new StringBuilder("<File xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:x=\"http://www.w3.org/2001/XMLSchema\" xmlns:s=\"http://schemas.microsoft.com/sitka/2008/03/\">");
builder.AppendFormat("<s:Id>{0}</s:Id>", Guid.NewGuid());
builder.AppendFormat("<file xsi:type=\"x:string\">{0}</file>", file.Name);
builder.AppendFormat("<folder xsi:type=\"x:string\">{0}</folder>", file.Directory.FullName);
builder.AppendFormat("<extension xsi:type=\"x:string\">{0}</extension>", file.Extension.Replace(".", string.Empty));
builder.AppendFormat("<size xsi:type=\"x:decimal\">{0}</size>", file.Length.ToString());
builder.AppendFormat("<content xsi:type=\"x:string\">{0}</content>", GoomezSearchHelper.Tokenizer.TokenizeToIndex(file.FullName));
builder.Append("</File>");


Here I’m writing the xml which represents an entity, in my case, called File. The file variable you see here is the FileInfo I passed as a parameter to this function.



Now the ‘magic’:



XElement entity = XElement.Parse(builder.ToString(), LoadOptions.SetLineInfo);

stm = new MemoryStream();
entity.Save(stm);
request.ContentLength = stm.Length;
using (Stream stream2 = request.GetRequestStream())
{
stream2.Write(stm.GetBuffer(), 0, (int)stm.Length);
}

response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode != HttpStatusCode.Created)
{
throw new WebException(string.Format(CultureInfo.InvariantCulture, "Unexpected status code returned: {0}", new object[] { response.StatusCode }));
}


Create the entity element, save it at a MemoryStream and get the response.



So, what was that? what did that do? if you go to the SDS Explorer and query the index you’ll see the file you just ‘uploaded’.



SDS Explorer

Read Full Post

Friday, December 12, 2008

Starting up with SQL Data Services (SDS)

SDS A few days ago I got my invitation code to the SQL Data Services CTP and last week I decided to take a peek of the ‘new technology’. Since I could not find a straight forward example of what to do when you want to test the SQL Data Services (FKA: SQL Server Data Services), I decided to post here a short version of what I did and hopefully someone will find here what I found in many places.

So, first of all I assume you already signed up for a SDS account at Microsoft Connect. They’ll send you two emails. The first one tells you your code to sign in but it also says the service is not available yet. And then, you get another email saying that the service in now available for you and that you need to sign in with the code they’d sent in the previous mail. Why don’t they send you just one mail when everything is ready? beats me!

And then what? well, is not easy… as I mentioned before, the site sucks big time. You need to go to the Azure site and click on the Sign In button at the top right corner. You might think you we’ll be prompted for user credentials, but no. Just click on Microsoft .Net Services & Microsoft SQL Data Services (or click my link). Now here you’ll have to sign in. Type your invitation code, the one they sent you in the first mail, here and click on Sign Up. Then you need to create a solution (remember this solution name for further reference). They also assign you a password (which you can change).

After that, click on the SDK link and download the Microsoft SQL Services SDK. After installing the so called ‘SDK’' open the SSDS Explorer. Read the doc to create and Authority, Containers and Entities (ACE is a mnemonic you might want to remember). I suggest you play around for a while before trying to write some code. Create Containers, and Entities. Create entities whit a different name (other than Entity) and same thing for the entity properties… notice you can write what ever you want there. Try some LinQ to query your entities.

In order to keep the post short I’ll show you some code in my next post.

Edit: I forgot to mention that the credentials asked by the SSDS Explorer are the name of the solution (the one you created before), and the password they gave (which hopefully you changed it)

Read Full Post