Wednesday, 22 September 2010

You cannot change the specified .NET Framework version

Hi Boys and Girls,

After converting an existent Solution from VS 2008 to VS 2010 I noticed that the Target Framework, for most projects, were kept to .NET Framework 3.5 with the only exception being my Test Project.

My Test Project had .NET framework 4.0 as the target framework. :-(

I tried manually to change the .NET framework back to 3. 5 and got this infamous error:












So basically I am stuck with having my Test Project targeting .NET 4.0 and my other projects targeting 3.5.

The $1000 question is : will the test units work? Thankfully they ran with out any issue. ;-)

The word from MS is:

Posted by Microsoft on 21/08/2009 at 12:58 AM

Thanks for your feedback. We are routing this bug to the product unit who works on that specific feature area. The team will review this issue and make a decision on whether they will fix it or not for the next release.

Thank you,
Visual Studio Product Team







Thursday, 9 September 2010

SSIS 2008 - Adding conversion data types


Last day I run into an issue while trying to import data from an excel workbook into some MSSQL 2008 tables.

On the setp "Review Data Type Mapping" of the Import/Export Wizard I got the infamous
red icon, next to two of the columns I wanted to import






Clearly the source data and the target data for those two columns are of different types and SSIS doesn't have a mapping between a Double and a nvarchar.

The mapping between SSIS data types are defined on a xml file located under the folder "Microsoft SQL Server\100\DTS\Binn" named DTUtil.exe.config
Luckily this XML file can be augmented to support conversions of others SSIS data types as long as the the the formatting of the target and source data types allow the conversion.





















First step is to discover what SSIS data types are the columns generating the issue.
On the Review Data Type Mapping screen I located one of the column experiencing the
unknown column type conversion and double click to see the conversation details.




















By looking on the Column Conversion Details I notice that the SSIS type of my source colum is (DT_R8)

Column Type: Double
SSIS Type: double-precision float [DT_R8]

and the SSIS type of the target or destination column is DT_TEXT.

Column Type: nvarchar
SSIS Type: Unicode text stream [DT_NTEXT]

Next I open the DtwTypeConversion.xml file using Tool for Men (aka Visual Studio)
By looking on the section for the DT_R8 type I confirmed that conversion of DT_R8
to DT_TEXT is not supported on the current mapping.













As a matter of fact my current mapping for the DT_R8 type only supports: conversion DT_R8 types to DT_DATE, DT_NUMERIC AND DT_DECIMAL

Time to add the DT_NTEXT type to this mapping to let SSIS knows that the conversion type of a Double to nvarchar is possible.

With the extra mapping for the conversion of double (DT_R8) to nvarchar(DT_NTEXT) added, this is the way this section of my DtwTypeConversion.xml looks like:



Important, things to consider:
1. Create a copy or back up of the DtwTypeConversion.xml before you modify it.
2. On window 7 and Server 2008 you will need to open the DtwTypeConversion.xml with
Administrator rights.
3. After applying the changes to the DtwTypeConversion.xml and before importing the
data, back up your database just in case your data lose precision.
4. if working with real data, this is data that will be used on a real application,
I would suggest you test this procedure on your developer environment to minimize
down time to either your clients or company.

Don't underestimate the power of the Dark Side.





Monday, 29 March 2010

The infamous EntityConnection error:

 

Hi Friends and neighbours ,

I encountered the infamous EntityConnection errror, “The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid....”
while unit testing one of  the business component for the solution that I am working on. This particular business component uses an Entity object.

if you have used the The ADO.NET Entity Framework  you know that you need to create the entity data model. When the entity data model or EDM is created using Visual Studio, in this case Visual Studio 2008, a file called “app.config” is also created. This file is created on the same level or should we say next to the EDM file.

project_setup


The app.config file contain the details of the database connection. Since my VS solution is broken up on different layers, one project for each layer, the EDM and app.config file were created on the Data Access layer Project hence my unit tests classes, located on the Test project level, were not able to find the connection details.

The solution : I simply made a copy of the app.config  file available to my Test business project.

TestBusiness

Now if you break up your solution into different projects, with each project representing a layer of your application, don’t forget to either, make a copy of the app.cofnig file available to your ASP NET project or alternative modify your web.config file with the connection string properties found in the app.config file.

Until next time,

“Don’t underestimate the power of The Dark Side”

Wednesday, 24 March 2010

ASP NET group validation

Hi Boy and Girls,

Group validation is a very handy feature of ASP NET. It let you use one validation for a related group of controls,

The scenario:

Let’s say we want to display a list of items that have been updated within a given period range.


text_boxes_control

We want our users to pick a date range, start and end date, and based on the dates picked our application will show the data.  On our UI We have provided one date picker for each text box.

date_picker 

Our application must handle, gracefully,
’abnormal’ scenarios.

Even that our above control has two date pickers, we must handle abnormal scenarios. On this simple example we can see two scenarios that our application must handle:

1. User forgets to input the date on one or both text boxes fields.
2. User doesn’t use the data picker provided by us but instead input the date directly

By looking on these two scenarios we can see that we need two validations for each input box.

ASP NET provide us with “Group Validation”. it is very easy to implement. Basically it is a  3 steps process.


1.  We add the property ‘ValidationGroup’ to each text box. As a value for this property We can use something like “TextBoxesGroup” so we end up with something like this:


<asp:TextBox ID="txtEndDate" ValidationGroup="TextBoxes" runat="server" />

2. We add our ASP NET validator components; Remember we need two of them: one to make our fields ‘required’ AKA compulsory and the other for enforcing the right date format.

So  we will add the <<asp:RequiredFieldValidator/> and the <asp:RegularExpressionValidator>components to our user control.

3. We add the property ValidationGroup to each of our validatos.  As a value for the ValidationGroup property we must specify the value that we used for the text boxes property ValidationGroup.

<asp:RequiredFieldValidator ID="RequiredValidator” runat="server" ValidationGroup="TextBoxes"
      ControlToValidate="txtStartDate"  ErrorMessage="your error message”" />

<asp:RegularExpressionValidator  ID="DateRegularExpressionValidator" ValidationGroup="TextBoxes"
        ValidationExpression="your RegEx expressions"
ControlToValidate="txtStartDate"   ErrorMessage="You error message" runat="server" />

4. We add the property ValidationGroup="TextBoxes" to the submit button.We will need this so our SearchProductsButton only validate the controls grouped under the TextBoxes validation group.

<asp:Button ID="SearchProductsButton" runat="server" OnClick="Search_Click" Text="Search Products" ValidationGroup="TextBoxes" />


Other solutions:

1.We could have built our validation on the server code, otherwise known as ‘code behind. This solution will cause the validation to be run on the server side, generating extra round trips.

2. Make our text boxes read-only. If we make our text boxes read only we will still able to populate them using JavaScript, however, If you try to retrieve the text box values, from the code that is tied to the user control or page, you will see only emptiness. Well not emptiness; You will see an empty string for each text box control value.

I tested my solution using IE 8 and Chrome and it worked on both of them.

If some one was able to retrieve the values of  read-only text boxes, from the code behind, let me know. :

-)

   Don’t underestimate the power of the dark side.

Tuesday, 2 February 2010

primitives


Hello Friends and Neighbours,

Having worked in the IT for several years I find that our tools, languages and platforms keep improving . All in the name of helping I.T practitioners to manage, tackle and solve more complex business problems.

Without doubt new languages improve over old or existent languages. C++ improved over C , Java improved over C++ and C# improved over Java.

Lets see a very simple example, a "milk for babies" kind of example:

I have an integer I want to convert it to a text (or string, as we developers call it)

In Java we would something like this:

int x = 1;
String aString = Integer.toString(x);

We need to call the static toString() method of the Integer class.

In C# we would do it like this:

int x = 45;
String aString = x.ToString();

In C# We are able to get the string representation, of the integer, right from the primitive itself!

With C# we are able to get the string represantion of a double expression:
Console.WriteLine((46.4 * 24.4).ToString());





There are other way of converting integer to string in Java. However, they are not as readable as the
one above.

http://en.literateprograms.org/Convert_Integer_to_String_(Java)