SQL Server does not Allow Remote Connections Error

When you create your DB Dude project and try to build and deploy the project to the client’s sandbox at the first time, you suddenly get the error:

“An error has occurred while establishing a connection to the server.  When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections.”

This error occurred because the networking protocols are disabled by default in SQL Server Express. In order to solve this problem you should configure SQL Server Express to accept remote connections.  I followed  this post’s (at SQL Express WebLog) instuctions and the problem was solved.

Advertisements

C# attributes

I asked too much by .NET developers about attributes and their meaning. I hope that this post will help you to understand it better.

Introduction: what are attributes?

An attribute is a powerful .NET language feature that is attached to a target programming element (e.g., a class, method, assembly, interface, etc.) to customize behaviors or extract organizational information of the target at design, compile, or runtime. It is a clean approach to associate metadata with program elements and later use the metadata at design, compile or run time to accomplish some common objectives. Attributes come in two flavors: intrinsic and custom. Intrinsic attributes are supplied as part of the Common Language Runtime (CLR), and they are integrated into .NET. Custom attributes are attributes you create for your own purposes. As a thumb-rule, a class is said to be an attribute class, if it directly or indirectly derives from the System.Attribute class. 

Why we need attributes?

For example, ObsoleteAttribute, causes a compile-time warning to appear, letting the developer know that a method should no longer be used. ; Attributes are also used extensively in securing .NET assemblies, forcing calling code to be evaluated against pre-defined security constraints. ; DllImportAttribute that allows a program to communicate with the Win32 libraries; and more…

Once associated with a program entity, the attribute can be queried at run time and used in any number of ways.

Using attributes

Attributes are placed before the item that they will be "decorating" and they are put inside square braces [].

To understand the power of attributes, consider the serialization of an object. In .NET, you just need to mark a class Serializable to make its member variables as Serializable. Serializable attribute: (type of SerializableAttribute)

 1
2
 [Serializable()]
public class CustomerData

I didnt use the SerializableAttribute class when applying the attribute to the class. The only time that you can leave off the Attribute portion of the name is when you are applying the Attribute to a class.

 1
2
3
4
5
6
7
8
9
10
11
12
 public  class MyClass
{
  [Obsolete("This method replaced by CalcEx method.", true)]
  static int Calc(int a, int b ) { }

  static int CalcEx (int a, int b ) { }

  public static void Main( )
  {
     int res = Calc(1,2);
  }
}

I used the attribute Obsolete, which marks a method (in this case) that should not be used. The first parameter is the string, which explains why the item is obsolete and what to use instead. In fact, you can write any other text here. The second parameter tells the compiler to treat the use of the item as an error. The default value is false, which means the compiler generates a warning for this.

When we try to compile this program, we will get an error with the message: MyClass.Calc is obsolete: 'This method replaced by CalcEx method.'

Custom attributes

When do you define your custom attributes? query at runtime!  For example, let's create CryAttribute class:

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 public  class CryAttribute : Attribute
{
  private string m_reason;
  public string Reason
  {
    get
    {
      {return m_reason;}
    }
  }

   public CryAttribute( string reason)  
  {
    m_reason = reason;
  }
}

Now, Let's use this attribute:

 1
2
3
4
5
6
7
8
9
 [Cry("Because babies cry..:)")]  // normal babies cry without reason
public class Baby
{
}

[Cry("The baby is hungry")] // The baby cry because he wants to eat
public class HungryBaby : Baby
{
}

It's great…but what can we do with it?? .NET gives us a new point of the view: runtime attributes querying.

How can we query?

 1
2
3
4
5
6
7
8
9
 public  string WhyTheBabyCry(Baby baby)
{
  Type type = baby.GetType();
    object obj = type.GetCustomAttributes()[0];// the first attribute 
  if(obj is CryAttribute)
    return ((CryAttribute)obj).Reason;
   else// other attribute
     return "First attribute is not Cry!";
}

Now we can use it:

 1
2
3
4
5
6
 Baby Baby1 =  new Baby();
Baby Baby2 = new HungryBaby();

string reason1,reason2;
reason1 = WhyTheBabyCry(Baby1);// receives "Because babies cry..:)"
reason2 = WhyTheBabyCry(Baby2);// "The baby is hungry"

More about attributes you can find at msdn.

Enterprise Library 3.1 Released

Enterprise Library 3.1 just Released: It is a maintenance release to fix a few bugs. It also includes an extension point in the Policy Injection Application Block that allows you to replace the injection mechanism.

Changes per Tom Hollander:

Policy Injection Application Block

  • The default Remoting Policy Injector can now be replaced with alternative interception mechanisms via configuration without modifying the application block code
  • Call Handler attributes are now honored correctly when placed on interface methods
  • Fixed an issue that could cause duplicate handlers where matching rules matched both a class and its interface
  • Classes implementing COM interfaces (including those deriving from System.Windows.Forms.Form) can now be intercepted
  • TraceLogEntry class is now serializable, allowing it to be used with the MSMQ Trace Listener

Validation Application Block

  • Fixed an issue that prevented the PropertyComparisonValidator from working with the Windows Forms integration adapter
  • The message template for the PropertyComparisonValidator can now be saved using the configuration tools.

Data Access Application Block

  • Connection strings for OLEDB and ODBC connections can now be edited using custom dialog boxes from the configuration tools

You can download it here.

WCF Articles

In order to introduce Windows Communication Foundation (WCF) I'm starting a series of posts here.

Most of the applications now requires to support the SOA architecture, means that the application should provide a service interfaces to be exposed to other applications. These interfaces can be exposed using many technologies: Web Services, COM+ and so on. Each technology is completely defferent from the other, and requires special knowledge of coding.

WCF makes life better. WCF helps developers to expose service interfaces using any technology. WCF has same set of functions and attributes that will be used for all technologies (bindings).

From every post I'll refer to this post and I'll keep a TOC here so you can easily navigate in the blog.

TOC:

  1. What is service ABC? Basic client/Server application.

WCAT 6.3 web performance and scalability test tool released!

The latest version of WCAT (Web Capacity Analysis Tool – the web performance test tool that the IIS team and NT Performance team use to conduct internal performance and scalability testing of IIS and ASP.NET) just released .

For more details and download, read: http://mvolo.com/blogs/serverside/archive/2007/05/17/WCAT-6.3-web-performance-and-scalability-test-tool-released.aspx.

My article at Patterns and Practices – VSTS Wiki

The patterns and practices VSTS team has created a project in CodePlex. Recently, they have opened it up to community contribution using a Wiki. I published there an article that discussing the synchronization between TFS and test director.

Google Launches New Design, Universal Search

Google’s pages has been changed today? You feel that something different about Google?

They have upgraded the site with Universal Search. You can read more at the official press release and at the official Google Blog post.

%d bloggers like this: