DBA in Space
Okay, I really love SQL, I find it clean sexy, beautiful.. functional and powerful…
It’s the programming language that comes closer to spoken english and it can do wonders.. either way I digress. My point is, if you love SQL as much as I do you can win a trip to space. Oh yeah, you heard me. SPACE!!!
https://www.dbainspace.com/
Send me a postcard if you will

What a gem!!!
Multiple files upload??
Yes, there’s about a gazillion libs out there to do it…. but the simplicity of this one is just too beautiful
http://davidwalsh.name/multiple-file-upload
Laters
Google + API
Yep, we’ve all been waiting for it and it’s finally here and although these + vs Facebook are getting quite old, the comparisons will be inevitable.
On a first glance, the first thing that strikes you is that Google, actually developed libs for each one of the languages the one thing Facebook is missing, badly. I mean programming for Facebook can be exhausting, in PHP. The worst thing is that if you try it any other language, you’re basically looking for trouble. This has been one my pet peeves against Facebook. Now, I haven’t actually tried Google + API but just this is a good start…
We’ll (try to) keep you posted as I dive in…
http://developers.google.com/+/
Laters
IT Security
Hiya,
A very good friend of mine, Ralf Braga, is organizing this convention, well worth checking out
http://www.just4meeting.com/2011/agenda.html
Table-Valued Parameters
Hiya,
Every now and then you came across a really, really nice article. A few days ago I came across this one about table-valued parameters. It summarizes everything really well and explains the old problem of sending list values as parameters into a stored procedure.
Kudos Mr. Erland Sommarskog’s
Error 0xc020209c: Data Flow Task 1:
Hi, today while importing a text file with 8 million records into SQL Server I got this error
Error 0xc020209c: Data Flow Task 1:…
This happened while using the import/export wizard. My web search was kinda depressing as well since I couldn’t find anything similar to my conditions so, I decided to try things out. What worked for me was, before importing the file I added an extra line on top (column name) with the same name as the destination column and then clicked on “Column names in the first row” after that I disabled the option “Enable identity insert” in the Edit Mappings part of the wizard and Voilá tt worked like a charm.
The access control list is not in canonical form…..
Hi,
While deploying to a brand new production server, using Visual Studio 2010, publish feature, I came across this error:
Error 6 Web deployment task failed.((19-05-2011 13:58:40) An error occurred when the request was processed on the remote computer.)
(19-05-2011 13:58:40) An error occurred when the request was processed on the remote computer.
This access control list is not in canonical form and therefore cannot be modified. 0 0 Applicationname
Which was a bit strange and got me sweating since I was the one who installed the Web Deployment Agent Service on said production server.
Well, no need to sweat this was actually a permissions problem with the newly created application and not the service.
After granting my user with the right permissions, it all worked fine.
Serialiaze to JSON in C#
Yesterday I was musing over the fact that I had to serialize a result objects to JSON so I could send it back to the view.
First quick intro on JSON (pronounced Jason) or JavaScript Object Notation. In this new ajax crazy world wide web a lot of people prefer JSON to XML, why? Well, not only c’os it’s ligher but because once you receive the response in JavaScript you can immediately start using the object notation. For instance if we had an object in our software called Person it’s JSON representation could be something like this:
-
{
-
-
"name": "William Shakespeare",
-
"nickname": "Bill"
-
"nationality" : "English"
-
}
This string, it’s interpreted by your JavaScript engine and you could then start doing something like this – person.name – to get the values, leaving aside all the XML parsing
Since I needed to convert my C# objects I started looking and I came across System.Web.Script.Serialization.JavaScriptSerializer which I used to help me created a base result object with a ToXml method
-
using System;
-
using System.Web.Script.Serialization;
-
-
namespace Test
-
{
-
[Serializable]
-
public class BaseResult
-
{
-
public bool Success { get; set; }
-
public string Message { get; set; }
-
-
public string ToJson()
-
{
-
var serializer = new JavaScriptSerializer();
-
var _this = serializer.Serialize(this);
-
return _this;
-
}
-
}
-
-
-
}
Well it turns out that if you’re programming in ASP.NET MVC you can return JSON as your response from the controller in a much simpler fashion
-
public JsonResult SomeAction()
-
{
-
Person person = new Person();
-
return this.Json(person);
-
}
The line this.Json(person) serializes you object without you having to do much else other than passing the parameter.
Okay that’s it for now… See you all soon
Upload from Flex to ASP.NET MVC
Today I’ve been working on upload between the Flex frontend and the ASP.NET MVC backend.
All rite so let’s get with it, starting with flex. The first thing you need to do, in order to pick which file you wanna upload is to instantiate a FileReference object. This object will do most of the work for you, allowing you browse and pick which file you want and then actually uploading it. As you can see by the code below I’ve added a couple of event listeners to it and and OnFileSelected the actual upload happens. Don’t forget to change url on URLRequest to the actual url you want, and would be something like:
http://name-of-your-server/name-of-the-controller/name-of-the-action
-
<?xml version="1.0" encoding="utf-8"?>
-
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
-
xmlns:s="library://ns.adobe.com/flex/spark"
-
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="OnCreationComplete(event)">
-
<fx:Script>
-
<![CDATA[
-
import mx.events.FlexEvent;
-
public var fileRef:FileReference = new FileReference();
-
-
-
protected function OnCreationComplete(event:FlexEvent): void {
-
fileRef.addEventListener(Event.SELECT, OnFileSeletected);
-
fileRef.addEventListener(Event.COMPLETE, OnUploadComplete);
-
}
-
-
public function OnFileSeletected(event:Event) : void {
-
var request:URLRequest = new URLRequest("http://name-of-your-server/FlexChannel/VideoUpload");
-
request.method = URLRequestMethod.POST;
-
try{
-
fileRef.upload(request);
-
}
-
catch(error:Error){
-
trace(error.message);
-
}
-
}
-
-
public function OnUploadComplete(event:Event) : void{
-
trace("complete");
-
}
-
-
-
public function OnOpenClicked(event:MouseEvent) : void{
-
fileRef.browse([new FileFilter("Videos", "*.mov;*.avi;*.mp4;*.mpeg")]);
-
}
-
-
]]>
-
</fx:Script>
-
<fx:Declarations>
-
<!– Place non-visual elements (e.g., services, value objects) here –>
-
</fx:Declarations>
-
<s:Button label="Upload" click="OnOpenClicked(event)"/>
-
</s:Application>
On the ASP.NET MVC side you, obviously, need to create a controller to handle those requests and within the controller this is the action that will handle the actual upload.
-
[HttpPost]
-
public ActionResult VideoUpload()
-
{
-
try
-
{
-
if (Request.Files != null && Request.Files.Count > 0)
-
{
-
var fileBase = Request.Files[0] as HttpPostedFileBase;
-
//make sure the file is not empty
-
if (fileBase.ContentLength > 0)
-
{
-
var extension = Path.GetExtension(fileBase.FileName);
-
var filename = string.Format(@"{0}{1}", Guid.NewGuid(), extension);
-
string path = string.Format(@"{0}\{1}", Server.MapPath(@"~\OriginalVideoFiles"), filename);
-
fileBase.SaveAs(path);
-
return Content("success", "text/xml");
-
}
-
}
-
return Content("Failure", "text/xml");
-
}
-
catch (Exception ex)
-
{
-
//TODO Error handling
-
return Content(string.Format("Failure: {0}", ex.Message), "text/xml");
-
}
-
}
If you’re familiar with uploads with Webforms you’ll see that not much has changed. I check whether there are files to be uploaded and then store them in the OriginalVideoFiles folder. The rest of the code is there to some renaming.
Okay that’s pretty much it. See you all soon
Modelling
Model
The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller).
In Model-View-Controller (MVC), Model is where you encapsulate the application’s state (therefore, it’s the layer that responds to state queries). In the real world, the model is more or less a replica of your database ER diagram.
After giving it some thought I ended up with that best way to explain what model is by creating a mock application, I admit that this is nothing new since there’s a very good tutorial of the same mold done by Microsoft. The music store application, a neatly packaged walk through that I highly recommend nevertheless my goal here is just to give you another perspective I doing the same thing. So what is that we’ll be doing here? Well I thought we’d keep it simple and just create a simple newsletter application, where users, after registration can receive newsletters of various dinner menus. I won’t be implementing the whole thing, c’os I have a day job, but rather focusing the functionalities that allow me to explain my point.
In an ideal world, as a developer, you’d be able to sit down and create the classes design (how objects will interact) and draw the database (how your data is stored) all of this while pondering all the consequences. But the truth is when you start developing, especially small applications, you barely have to time to scratch since everything is expected to be ready by yesterday. I bring this point c’os it’s important in the sense that’s why most developers use the database design to create the model.
So if you consider these tables:

You could then create this as your model with some changes, in the database design I needed to create an extra table (UserFoodPreferences) with a 1 > n relationships, while in the class design I simply need to add a List to the ApplicationUser class (List<FoodItem> FoodPreferences). This has, obviously to do with the data structures that we have available for each type of development, while in SQL you have to rely on relationships to store complex data, in C# you have “native” structures that allow you to do. My class diagram would look something like this:
Because the model usually mirrors what’s in the database you can also use de ADO.NET Entity Data Model. The ADO.NET will definitely make your life much easier by generating the code that does all the plumbing for you.
Before I sign off, I’d like to remind you that although I talk a lot about the Model mirroring the database. It doesn’t have to be like that, you can actually define a model that has nothing to do with how it’s stored in the database. Actually that the whole point of MVC is to allow to separate the various layers. On my next post I will talk about Controllers which will allow to post some code that will exemplify some of the things we’ve just talked about…
Take good care of yourselves

