Monday, May 28, 2007

VSTS for database professionals installation requirements

A lot of users feel confused about the installation requirements of VSTS for DB Professionals (DB Pro).

"Team Suite or other product must be installed before Db Pro" as the ReadMe file says.

The requirements of VSTS for Database Professionals are:

  • Visual Studio Professional Edition/Visual Studio Team Suite. Team Edition for Database Professionals is available as a separate product; however, to evaluate the Team Edition for Database Professionals Trial you must first install the Visual Studio 2005 Team Suite 180-Day Trial.
  • The Visual Basic or C# language feature must be installed.
  • MSXML must be installed.
  • Visual Studio Professional Edition is included on the DVD for Visual Studio Team Edition for Database Professionals.

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.

Saturday, May 26, 2007

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.

Friday, May 18, 2007

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.

Thursday, May 17, 2007

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.

VSTS for database professionals installation requirements

A lot of users feel confused about the installation requirements of VSTS for DB Professionals (DB Pro). The readme file says:

"Team Suite or other product must be installed before Db Pro".

The requirements of VSTS for Database Professionals are:

  • Visual Studio Professional Edition, Visual Studio Team Suite, or one of the role-based SKU's of Visual Studio Team System. The trial version of Visual Studio Team Edition for Database Professionals requires Visual Studio Team Suite.
  • The Visual Basic or C# language feature must be installed.
  • MSXML must be installed.
  • Visual Studio Professional Edition is included on the DVD for Visual Studio Team Edition for Database Professionals.

also posted at: http://blogs.microsoft.co.il/blogs/maordavid/default.aspx

Wednesday, May 16, 2007

DB Dude - Error & Warning messages

What does error message TSD4001 means? Or TSD3025?

How can you filter out db dude's warning messages?

A great list that summarizes and explains the warning and error messages of db dude and the way to filtering warning messages, you can find at  gert's post.

Check it out.

Disabling triggers to support data generation on DB Dude

When deploying test data to database (such as your sandbox database) with triggers, you need that the triggers will be disabled before generating test data and then re-enabled after the data has been appropriately generated.

I wrote two scripts for this issue: DisableTriggers.sql , EnableTriggers.sql .

Execute this T-Sql before deploying test data:

DisableTriggers.sql

IF EXISTS ( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'#AllTriggers') AND type in (N 'U'))
DROP TABLE #AllTriggers


--Getting all trigger names ad on what tables and schemas they reside:
--Put the list in a temp tab
SELECT T.Name as TrigName, o.Name as TabName, s.Name as SchemaName
INTO #AllTriggers
FROM sys.triggers T join sys.objects o
ON T.parent_Id = o. object_ID
JOIN sys.schemas s
ON o.schema_Id = s.Schema_ID


--Disabling all triggers: A cursor to run over the temp table
DECLARE TrigCurs Cursor
FOR SELECT TrigName, TabName, SchemaName FROM #AllTriggers

OPEN TrigCurs

DECLARE @TrigName varchar(250), @TabName varchar(250), @SchameName VarChar(250), @cmd varchar(1000)

FETCH Next FROM TrigCurs INTO @TrigName , @TabName , @SchameName

WHILE @@Fetch_Status = 0
BEGIN
SET @cmd = 'disable trigger all on '+ @SchameName+ '.'+@TabName+';'
EXEC (@cmd)

FETCH Next FROM TrigCurs INTO @TrigName , @TabName , @SchameName
END
GO

I execute it from the Script.PreDeployment.sql  file.

Re-enable them after the data was generated. The T-Sql is:

EnableTriggers.sql

--Enabling back all triggers: A cursor to run over the temp tab
DECLARE TrigCurs2 Cursor
FOR SELECT TrigName, TabName, SchemaName from #AllTriggers

OPEN TrigCurs2

DECLARE @TrigName varchar(250), @TabName varchar(250), @SchameName VarChar(250), @cmd varchar(1000)

FETCH Next from TrigCurs2 into @TrigName , @TabName , @SchameName

WHILE @@Fetch_Status = 0
BEGIN
SET @cmd = 'enable trigger all on '+ @SchameName+ '.'+@TabName+';'
EXEC (@cmd)

FETCH Next FROM TrigCurs2 INTO @TrigName , @TabName , @SchameName
END

DROP TABLE #AllTriggers
GO

I execute it from the Script.PostDeployment.sql  file.

You can download both scripts: EnableTriggers.sql , DisableTriggers.sql

Saturday, May 12, 2007

Silverlight introduction

At Mix07, Microsoft announced Silverlight™.

Microsoft® Silverlight™ is a cross-browser, cross-platform plug-in for delivering the next generation of .NET based media experiences and rich interactive applications for the Web.

You can read more here (SilverLight site), its amazing!

Great post about Silverlight UI Controls, by Ashish Shetty, you can find here.

Slides and demos you can download from Nikhil Kothari's Weblog.

Enjoy!

How to: Calling Web Services methods from Client Script in ASP.NET AJAX

My previos post explained the way to expose a web service to client script in Ajax. This post will introduce the "How to" call the web service's method from the client script.

Our web service is:

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  namespace MySamples.BL
{
[WebService(Namespace = " http://tempuri.org/")]
[ScriptService]
public class MyWebService : System.Web.Services.WebService
{
[WebMethod]
public string PrintString(String input)
{
return input;
}
[WebMethod]
public string SayHello()
{
return "Hello";
}
}
}

Calling a Web service method from script is asynchronous. Succeeded callback function must provided to get a return value or to determine when the request has returned. This function is invoked when the request has finished successfully with return value (as a parameter) from the Web method call. Failed callback function can also provided to handle errors.

Based on the previous post, this is what you should do in the client script.

The script is:

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  // This function calls the Web service method 
// without parameters and
// passes the event callback function.
function SayHello()
{
MySamples.BL.MyWebService.SayHello(SucceededCallback);
}

// This function calls the Web service method
// passing simple type parameters and the
// callback function 
function PrintString(str)
{
    MySamples.BL.MyWebService.PrintString(str,SucceededCallback);
}


// This is the callback function invoked if the Web service succeeded.
function SucceededCallback(result, eventArgs)
{
    var wsResult= document.getElementById( "wsResult");
    wsResult.innerHTML = result;
}

Thats all!

Friday, May 11, 2007

Another blog

Hi

I also blogging at Microsoft community - Maor David's blog.

The address is: http://blogs.microsoft.co.il/blogs/maordavid/default.aspx

You are welcome!

Maor

How to: Expose Web Services to Client Script in AJAX

AJAX enables you to call ASP.NET Web services by using client script. There are several steps to enable the web service exposing.

1. Qualify the Web service class with the ScriptServiceAttribute attribute:


1
2
3
4
5
6
7
8
9
[ScriptService]
public class MyWebService : System.Web.Services.WebService
{
[WebMethod]
public string PrintString(String input)
{
return input;
}
}


2. Configure the Web application to support calling Web services from script. Register the ScriptHandlerFactory HTTP handler in the Web.config file for the application:


<system.web>
   <httpHandlers>
      <remove verb="*" path="*.asmx"/>
      <add verb="*" path="*.asmx" type="System.Web.Script.Services.ScriptHandlerFactory" validate="false"/>
   </httpHandlers>
<system.web>


Note: The handler delegates the call to the default handler for Web service calls that are not issued from AJAX script.


3. Enable the Web service to be called from script in an ASP.NET Web page:


<asp:ScriptManager runat="server" ID="scriptManager">
   <Services>
      <asp:ServiceReference path="~/BL/MyWebService.asmx" />
   </Services>
</asp:ScriptManager>


Note: The ServiceReference object can reference a Web service only in the same domain.


JavaScript proxy class for the .asmx Web Service created by the page that contains the ScriptManager control. It occures when this page is rendered. The proxy class has methods that correspond to each Web method in the MyWebService.asmx service.


The next post will be about the way to call the Web Service.


 


del.icio.us tags: , ,

Monday, May 7, 2007

Team Project: What? Why? How?

Over the last year I frequently asked by our customers "What is the best way to structure my team projects?".
This is a good question!
And the answer?....

Miscrosot produced a whitepaper (Guidance for Structuring Team Projects) that summarizes the factors to consider when making this choice.

Sunday, May 6, 2007

Public CTP for VSDBPro Service Release 1 is now available

The public CTP for the first service release of Visual Studio Team Edition for Database Professionals just released.
For all the details, please check out Gert's post right here.

Interface vs Abstract Class

I frequently asked what is the difference between Interface and Abstract classes. The main difficulty is the choice of whether to design your functionality as an interface or an abstract class.


Interface
An interface is a reference type containing only abstract members. These can be events, indexers, methods or properties, but only the member declarations. A class implementing an interface must provide the implementation of the interface members. An interface cannot contain constants, constructors, data fields, destructors, static members or other interfaces. Interface member declarations are implicitly public.
An interface declaration may declare zero or more members.
All interface members implicitly have public access. It is a compile-time error for interface member declarations to include any modifiers. In particular, it is a compile-time error for an interface member to include any of the following modifiers: abstract, public, protected, internal, private, virtual, override, or static.



Abstract class
Like an interface, you cannot implement an instance of an abstract class, however you can implement methods, fields, and properties in the abstract class that can be used by the child class.
The abstract modifier is used to indicate that a class is incomplete and that it is intended to be used only as a base class. An abstract class differs from a non-abstract class is the following ways:
An abstract class cannot be instantiated directly, and it is a compile-time error to use the new operator on an abstract class. While it is possible to have variables and values whose compile-time types are abstract, such variables and values will necessarily either be null or contain references to instances of non-abstract classes derived from the abstract types.
An abstract class is permitted (but not required) to contain abstract members.
An abstract class cannot be sealed.
When a non-abstract class is derived from an abstract class, the non-abstract class must include actual implementations of all inherited abstract members
The purpose of an abstract class is to provide a base class definition for how a set of derived classes will work and then allow the programmers to fill the implementation in the derived classes.


List of similarities and differences between an interface and an abstract class:
  • In practice,an interface is a good way to encapsulate a common idea for use by a number of possibly unrelated classes, while an abstract class is a good way to encapsulate a common idea for use by a number of related classes.
  • When you need to provide common, implemented functionality among all implementations of your component, use an abstract class. Abstract classes allow you to partially implement your class, whereas interfaces contain no implementation for any members.
  • An Interface can only inherit from another Interface, when an abstract class can inherit from a class and one or more interfaces
  • An Interface cannot contain constructors or destructors, when abstract class can contain constructors or destructors.
  • An Interface can be inherited from by structures,when abstract class cannot be inherited from by structures.
  • An Interface can support multiple inheritance,when abstract class cannot support multiple inheritance.
  • Interfaces are used to define the peripheral abilities of a class;An abstract class defines the core identity of a class and there it is used for objects of the same type.
  • If we add a new method to an Interface then we have to track down all the implementations of the interface and define implementation for the new method; If we add a new method to an abstract class then we have the option of providing default implementation and therefore all the existing code might work properly.

Saturday, May 5, 2007

Israeli ALM User Group - Third meeting

The third meeting will take place on the 12 of May in Microsoft offices in Raanana.
Meeting subject: Team Buiid capabilites including extnesive customization issues.

You can read Sarit's post to get more details.

Friday, May 4, 2007

Microsoft announced Silverlight

At Mix07, Microsoft announced Silverlight™.

Microsoft® Silverlight™ is a cross-browser, cross-platform plug-in for delivering the next generation of .NET based media experiences and rich interactive applications for the Web.

You can read more here (SilverLight site), its amazing!

Great post about Silverlight UI Controls, by Ashish Shetty, you can find here.