Tuesday, November 25, 2008

New certification from Microsoft 70-441

Posted on/at 1:30 AM by Admin

Yesterday I passed 70-441 by score of 966. Exam Details

PRO: Designing Database Solutions by Using Microsoft SQL Server 2005 exam

Here are some notes about it:

- It has 6 testlets that contains 56 questions
"Testlet is actually a scenario based set of questions, covers from 5 to 12 questions"

1- A. Datum Corporation
2- Woodgrove Bank
3- Trey Research
4- Consolidated Messenger
5- Southridge Video
6- Coho Vineyard&Winery

- Each scenario consists of sections like:

- BACKGROUND
- EXISTING ENVIRONMENT
- BUSINESS REQUIREMENTS
- TECHNICAL REQUIREMENTS

- You can view scenario sections anytime while answering questions
- Each testlet has its own time limit, which tests your design capabilities under stress


I readed the books
- MCITP-Self-Paced-Training-Kit-Exam-Designing-Database-Solutions-by SQL 2005
- MCTS-certification-Microsoft-SQL-Server-2005-Database-Essentials-Step-by-Step
- Microsoft-SQL-Server-TM-2005-Applied-Techniques-Step-by-Step

Monday, November 24, 2008

Microsoft SQL Server 2005 New Features

Posted on/at 5:23 AM by Admin

Contents:


  • Using SQL Server Configuration Manager
  • Using SQL Server Surface Area Configuration
  • Using Surface Area Configuration for Services And Connections
  • Using Surface Area Configuration For Features
  • Using Dependencies
  • Using SQL Server Management Studio Templates


SQL server 2005 has many tools to help you analyze behavior, enable features, and study and enhance the performance of your server. The following sections will describe some of these tools.

1- Using SQL Server Configuration Manager

It is a Microsoft Management Console application that allows you to configure SQL Server 2005’s installed services, network configuration, and network protocols.

You can perform actions such as starting, pausing, and stopping services as well as defining the SQL Server and SQL Native Client network configuration.

Open it from
Start menu à choose All Programs à Microsoft SQL Server 2005 à Configuration Tools à SQL Server Configuration Manager



It can be used for running, stopping and restarting SQL Server services which are:

o SQL Server Integration Services
o SQL Server Full-Text Search Services
o SQL Server
o SQL Server Analysis Services
o SQL Server Reporting Services
o SQL Server BrowserSQL Server Agent




Using the SQL Server 2005 Network Configuration Node

It allows you to configure the network protocols used by each SQL Server instance by enabling or disabling the protocol.



Aliases:

Aliases are alternate names that can be used to connect to a SQL Server instance. Egypt_Server_Test will be the alias name that maps to the SQL Server instance egypt-aeid\Products , using the TCP/IP network protocol with port number 1433


2- Using SQL Server Surface Area Configuration

It is a tool that helps you enable, disable, start, or stop the features and services of your local and remote SQL Server 2005 installations. Stopping and disabling unused services allows you to reduce the surface area and makes your system more secure.

Open it from
--> Start menu --> choose All Programs --> Microsoft SQL Server 2005 --> Configuration Tools --> SQL Server Surface Area Configuration



2.1 Using Surface Area Configuration For Services And Connections

It allows you to configure the state of SQL Server services. You can stop, pause, resume, and start the SQL Server instance services. Moreover, you are able to configure whether the SQL Server instance will allow remote connections and, if so, which protocols to use



- Database Engine
- Analysis Services
- Reporting Services
- SQL Agent
- Full-Text Search
- Integration Services
- SQL Server Browser

All components have Service item for managing service settings:


Startup type : Use to configure how the service starts.
Automatic specifies that the service starts when the system starts.

Manual specifies that a user or dependent service can start the service, and that the service does not start when the system starts.

Disabled prevents the service from being started by the system, a user, or any dependent service.

Service status : Shows the status of the service.

Remote Connections for
- Database Engine
- Reporting Services

It is used to change the protocols on which SQL Server listens for incoming client connections. TCP/IP is preferred over named pipes because it requires fewer ports to be opened across the firewall



Local connections only
If selected, the Database Engine instance will only listen for shared memory connections on the local computer. Connections from remote computers will fail.

Local and remote connections
If selected, the Database Engine instance will listen for connections from the local computer and from remote computers using the selected protocols.

Using TCP/IP protocol only
If selected, the Database Engine instance listens for remote connections using TCP/IP, but not named pipes.

Using Named Pipes protocol only
If selected, the Database Engine instance listens for remote connections using named pipes, but not TCP/IP.

Using both TCP/IP and Named Pipes protocols
If selected, the Database Engine instance listens for remote connections using TCP/IP and named pipes.

2.2 Using SQL Server Surface Area Configuration for Features

It provides a single interface for enabling or disabling many Database Engine, Analysis Services, and Reporting Services features. Disabling unused features helps to secure your Microsoft SQL Server installations by reducing the SQL Server surface area.



SQL Mail, which is deprecated in favor of Database Mail, is disabled by default. Using this dialog, you can enable SQL Mail for backward compatibility.

3- Using Dependencies

Some database objects have dependencies upon other database objects. For example stored procedures may depend on objects like functions, tables, views …etcYou find dependencies by right click on any database object like tables, views, sp , fn ….etc





There are 2 types of dependencies for an object:

a- Objects that depend on

It displays a list of those objects that are dependency-tracked and that depend on the selected object.



b- Objects on which depends

It displays a list of those objects that are dependency-tracked, on which the selected object depends.



Using SQL Server Management Studio Templates

Templates are files that contain SQL scripts to help you create objects in the database.
You can create objects such as
o Databases
o Tables
o Views
o Indexes
o Stored procedures
o Triggers
o Statistics
o Functions

Open it from

Open SQL Server Management Studio --> View Menu --> Template Explorer
Find the sql files on hard disk from

"C:\Documents and Settings\\Application Data\Microsoft\Microsoft SQL Server\90\Tools\Shell\Templates"




Lets Create Stored Procedure ( New Menu )

Note: you can do the same step from the object explorer to a database, under programmability Stored Procedure, then by right click on that node


















Note: the created template contains many params and names needed to renamed, you can do that by the use of wizard (Ctrl + Shift + M)



Note: if you press OK, you won’t modify the names by wizard again.

Sunday, November 9, 2008

Provider Design Patterns in NET 2.0

Posted on/at 11:56 PM by Admin


I posted that article to CodeProject.com  Read

Download ProviderDesignPattern.zip - 4.01 MB
  • Introduction
  • What are the benefits of the article ?
  • Application Architecture
  • Application Configuration
  • Provider Implementation
  • Restoring Database
  • Debugging code
  • Conclusion
  • References

Introduction

Provider Design Pattern is a new pattern that Microsoft formalized in ASP.NET Whidbey. The pattern was officially named in the summer of 2002 when Microsoft was designing Whidbey's new Personalization feature.

Benefits of Provider
  1. No need to explicitly instantiate classes. The .NET framework will automatically manage class instantiation, including re-using classes that have already been instantiated. This will greatly improve the memory management of your application.


  2. Switching data sources is much easier. Changing the source of data for your application from the current database to any database, whether SQL Server, Oracle, XML, or other, is a simple as replacing your existing concrete (implementer) class with a new concrete (implementer) class and inheriting from your provider class. That is all. Your presentation and business logic layers remain unchanged, thereby reducing effort required to switch data sources and the amount of regression testing required thereafter.

  3. Learning the Provider Design concept will make it very easy to customize built-in .NET framework providers.
A provider implementation must derive from an abstract base class, which is used to define a contract for a particular feature.

For example, to create a Person provider for SQL, you create a new class SqlPersonProvider, which derives from PersonProvider. The base class of PersonProvider is ProviderBase . The ProviderBase class is used to mark implementers as a provider and forces the implementation of a required method and property common to all providers.

image32.png

What are the benefits of the article ?

- Understanding the implementation of Provider Design Pattern
- Understanding the implementation of 3-tier architecture application
- Understanding the application architecture
- Naming Conventions

Note: I strongly suggest that you use the exact names that I use in this document to develop your solution for the purpose of learning this concept. Once you have tested and understand how it works, then you can integrate your own naming conventions.

Application Implementation

I developed an application, Phone Book, as desktop application to describe the provider idea.

The phone book application was developed with the use of 3 tier architecture as shown on application architecture.

Database objects like tables, fields and stored procedures are represented by object oriented classes, properties and methods on the provider infos of CompanyName library

image26.JPG
The presentation layer calls the result from business logic layer and then data retrieved from database by the use of providers implemented at data access layer library.

Solution Projects [ 4 Projects]:

  1. BusinessLogicLayer : The business logic layer of the application


  2. CompanyName: it includes the global classes to all solution's projects


  3. DataAccessLayer: The data access layer of the application


  4. PhoneBookApplication: The presentation layer


image27.png

Application Architecture

The following figure depicts the common tiers of a distributed application. This document distinguishes between business data and the business processes that use the data; the business process tier is discussed only where needed for clarification. Likewise, the presentation tier is discussed only where there are direct implications for the way data is represented, such as the way Microsoft® ASP.NET Web pages expose business data.  Read More

image33.png

the following diagram describes the architecture of all solution's projects:

image28.png

The following diagram, ERD, is the database design of phonebook

image29.png


The following diagram, Use-Case diagram, describe the main functionality of the application:

image30.png

Now, we can discuss the implementation of each project:

(1) Open Visual Studio 2005

1- Create Windows Application and name it PhoneBookApplication
2- Choose File Menu --> Add --> New Project and name it BusinessLogicLayer
3-
Choose File Menu --> Add --> New Project and name it DataAccessLayer
4-
Choose File Menu --> Add --> New Project and name it CompanyName CompanyName :

this project will include common libraries that are globally used in the development and shared objects among projects
so you will add reference for CompanyName library to all other applications.

ex. i created the provider info classes to be shared among the "BussinessLogicLayer" and "DataAccessLayer" projects

image5.png

(2) Add Reference to the below DLLs for the BusinessLogicLayer and DataAccessLayer
  • System.Web
  • System.Configuration
  • CompanyName
(3) Add references of "CompanyName" and "BusinessLogicLayer" to the desktop application

image6.png

(4) Configuaring the App.config of the "PhoneBookApplication"

image8.png if you look to the xml elments in app.config, we define seciongroup named "PhoneBook" and added 2 sections to it which are "Person" and "Group"
<sectionGroup name="PhoneBook">
<section name="Person" type="CompanyName.PhoneBook.DataAccessLayer.SectionConfig, DataAccessLayer" />
<section name="Group" type="CompanyName.PhoneBook.DataAccessLayer.SectionConfig, DataAccessLayer" />
</sectionGroup>

then define that section group as:
<PhoneBook>
<Person>
<providers>
<add name="SqlPerson" type="CompanyName.PhoneBook.DataAccessLayer.SqlPersonProvider, DataAccessLayer"
connectionStringName="strcon" />
<add name="OraclePerson" type="CompanyName.PhoneBook.DataAccessLayer.OraclePersonProvider, DataAccessLayer"
connectionStringName="OracleConnection" />
<add name="AccessPerson" type="CompanyName.PhoneBook.DataAccessLayer.AccessPersonProvider, DataAccessLayer"
connectionStringName="AccessConnection" />
</providers>
</Person>
<Group>
<providers>
<add name="SqlGroup" type="CompanyName.PhoneBook.DataAccessLayer.SqlGroupProvider, DataAccessLayer"
connectionStringName="strcon" />
</providers>
</Group>
</PhoneBook>

then define the connection strings for data stores of "SQL, Oracle and Access"
<connectionStrings>
<add name="strcon" connectionString="Data Source=.;Initial Catalog=AhmedEid_PhoneBook;Integrated Security=True" />
<add name="OracleConnection" connectionString="oracle_connection_string" />
<add name="AccessConnection" connectionString="Access_connection_string" />
</connectionStrings>

person provider could retrieve data from SQL,Oracle or Access database.
Group provider could retrieve data from SQL only (5) Implementing DataAccessLayer Suppose PhoneBook is a midsize business and the PhoneBookApplicaion contains 2 major sections: - Person : profile management
- Groups : categorization of persons The following code reads all providers defined in your web.config. That is all you have to do to make providers information available to other classes.
using System;
using System.Configuration;
namespace CompanyName.PhoneBook.DataAccessLayer
{
public class SectionConfig : ConfigurationSection
{
[ConfigurationProperty("providers")]
public ProviderSettingsCollection Providers
{
get
{
return (ProviderSettingsCollection)base["providers"];
}
}
}
}

We need to create another class to have access to the Framework provider collection and to add our new provider(s) to the provider collection.
using System;
using System.Configuration.Provider;
namespace CompanyName.PhoneBook.DataAccessLayer
{
public class ProviderList : ProviderCollection
{
public override void Add(ProviderBase provider)
{
if (provider == null) throw new ArgumentNullException("The provider parameter cannot be null.");
base.Add(provider);
}
}
}

Create another class that will initialize the provider by the provider name.

example: initialize the Group provider for SQLGroupProvider class using provider name of "SQLGroup"
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Configuration;
using System.Configuration;
using CompanyName.PhoneBook.DataAccessLayer;

namespace CompanyName.PhoneBook.DataAccessLayer
{
public abstract class InitMember<T>
{
public static ProviderList Providers(string _providerSectionName)
{
SectionConfig qc = (SectionConfig)ConfigurationManager.GetSection(_providerSectionName);
providerCollection = new ProviderList();
// this wl instatiate PersonProvider with the class "personimpl" which inherit it
ProvidersHelper.InstantiateProviders(qc.Providers, providerCollection, typeof(T));
providerCollection.SetReadOnly();
return providerCollection;
}

private static ProviderList providerCollection;
}
}

The class takes the provider you want to initialize, i.e PersonProvider, its class and the provider name

This enum founded on CompanyName.Globals class

image13.png
using that class from the Instance method of PersonProvider Class:
        /// <summary>
/// This will initialize the provider and add instanse to the providers list
/// </summary>
/// <param name="_Provider"></param>
/// <returns></returns>
public static PersonProvider Instance(Globals.Providers _Provider)
{
return (DataAccessLayer.PersonProvider)DataAccessLayer.InitMember
<DataAccessLayer.PersonProvider>.Providers("PhoneBook/Person")[_Provider.ToString()];
}

This method will initialize the provider and add instance to the providers list

Now our "DataAccessLayer" project has the necessary classes for all providers to be later developed.

so we are going to develop two providers:

- PersonProvider
- GroupProvider


  • Now, we create our provider model:

    BaseProvider --> xxxProvider --> SQLxxxProvider xxx is the name of entity like Person, Group, ....etc Person Provider Classes:

    image9.png

    Group Provider Classes:


    image10.png
    Let me explain the implementation of the PersonProvider and you can create GroupProvider by yourself: first we create a class named "PersonProvider.cs"


    using System;
    using CompanyName.PhoneBook.Providers;
    using System.Configuration.Provider;
    using System.Configuration;
    using System.Web.Configuration;

    namespace CompanyName.PhoneBook.DataAccessLayer
    {
    public abstract class PersonProvider : ProviderBase
    {
    /// <summary>
    /// This will initialize the provider and add instanse to the providers list
    /// </summary>
    /// <param name="_Provider"></param>
    /// <returns></returns>
    public static PersonProvider Instance(Globals.Providers _Provider)
    {
    return (DataAccessLayer.PersonProvider)DataAccessLayer.InitMember
    <DataAccessLayer.PersonProvider>.Providers("PhoneBook/Person")[_Provider.ToString()];
    }
    /// <summary>
    /// Add new person
    /// </summary>
    /// <param name="_info"></param>
    /// <returns></returns>
    public abstract bool Add(PersonInfo _info);
    /// <summary>
    /// Modify selected person
    /// </summary>
    /// <param name="_info"></param>
    /// <returns></returns>
    public abstract bool Modify(PersonInfo _info);
    /// <summary>
    /// Delete selected person
    /// </summary>
    /// <param name="_PersonId"></param>
    /// <returns></returns>
    public abstract bool Delete(int _PersonId);
    /// <summary>
    /// Get all personns
    /// </summary>
    /// <returns></returns>
    public abstract PersonInfo[] Find();
    /// <summary>
    /// Get info of person
    /// </summary>
    /// <param name="_PersonId"></param>
    /// <returns></returns>
    public abstract PersonInfo GetInfo(int _PersonId);
    /// <summary>
    /// Get personns that match a given criteria
    /// </summary>
    /// <param name="_Searchinfo"></param>
    /// <returns></returns>
    public abstract PersonInfo[] Find(SearchCriteriaInfo _Searchinfo);
    }
    }

    Instance() method : is responsible for instantiating our concrete (implementer) class (SqlGeneralProvider.cs), which has been defined within Web.config. and "PersonProvider" abstract class, which it inherits from ProviderBase and include person abstracted functions. (6)

    BusinessLogicLayer
    image14.png

    Note:
    It is a good idea to add a Helper class into your BusinessLogicLayer project. This way, you can expose some common functionality to all of your BusinessLogicLayer classes just by inheriting from this helper class.
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Web;
    namespace CompanyName.PhoneBook.BusinessLogicLayer
    {
    /// <summary>
    /// You can use helper to provide common info./data needed OR to massage or add more info.
    /// to your data before sending it to presentation.
    /// </summary>
    public abstract class Helper
    {
    protected static string MachineName
    {
    get
    {
    return Environment.MachineName;
    }
    }
    }

    // Add more methods/properties below
    }

    then define the business classes for the Person and Group providers.

    Person.cs
    using System;
    using System.Collections.Generic;
    using System.Text;
    using CompanyName.PhoneBook.Providers;
    using CompanyName.PhoneBook.DataAccessLayer;

    namespace CompanyName.PhoneBook.BusinessLogicLayer
    {
    public abstract class Person : Helper
    {
    static PersonProvider objPersonProvider;
    /// <summary>
    /// Person Cnstructor
    /// </summary>

    //Class Constructor: will be invoked 1 time only / Appdomain
    static Person()
    {
    objPersonProvider = PersonProvider.Instance(Globals.Providers.SqlPerson);
    }
    // staticed methods for person
    /// <summary>
    /// Add new person
    /// </summary>
    /// <param name="_info"></param>
    /// <returns></returns>
    public static bool Add(PersonInfo _info)
    {
    // You can use helper to provide common info./data needed OR to
    // massage or add more info. to your data before sending it to
    // presentation.
    // Here we use helper class to get MachineName and pass it along
    // with data to presentation.
    return objPersonProvider.Add(_info);
    }
    /// <summary>
    /// Modify selected person
    /// </summary>
    /// <param name="_info"></param>
    /// <returns></returns>
    public static bool Modify(PersonInfo _info)
    {
    return objPersonProvider.Modify(_info);
    }
    /// <summary>
    /// Delete selected person
    /// </summary>
    /// <param name="_PersonId"></param>
    /// <returns></returns>
    public static bool Delete(int _PersonId) { return objPersonProvider.Delete(_PersonId); }
    /// <summary>
    /// Get all personns
    /// </summary>
    /// <returns></returns>
    public static PersonInfo[] Find() { return objPersonProvider.Find(); }
    /// <summary>
    /// Get info of person
    /// </summary>
    /// <param name="_PersonId"></param>
    /// <returns></returns>
    public static PersonInfo GetInfo(int _PersonId) { return objPersonProvider.GetInfo(_PersonId); }
    /// <summary>
    /// Get personns that match a given criteria
    /// </summary>
    /// <param name="_Searchinfo"></param>
    /// <returns></returns>
    public static PersonInfo[] Find(SearchCriteriaInfo _Searchinfo) { return objPersonProvider.Find(_Searchinfo); }
    }
    }

    define objPersonProvider as PersonProvider to be shared among the instances of Person class. Then initialize it on the class constructor which will be invoked for one time/ Appdomain
    Person objPerson_1 = new Person();  // on class A
    Person objPerson_2 = new Person(); // on class B
    Person objPerson_3 = new Person(); // on class C
    //Class Constructor: will be invoked 1 time only / Appdomain
    static Person()
    {
    objPersonProvider = PersonProvider.Instance(Globals.Providers.SqlPerson);
    }

    The objPersonProvider will be initialized with the objPerson_1 constructor only on the class A, then other instances like objPerson_2 or objPerson_3 will use the static object objPersonProvider. you can add you business logic to every method before calling the data access provider as
    public static bool Add(PersonInfo _info)
    {
    // Here: you can add you business logic to every method before calling the data access provider
    return objPersonProvider.Add(_info);
    }


    PhoneBook Application


    The presentation layer as desktop application for implementing the business logic to the client. <image31>

    How to use the BL layer from the presentation layer ? sample code
    // build the search criteria
    SearchCriteriaInfo objSearchInfo = new SearchCriteriaInfo();
    objSearchInfo.FilterNameBy = (Globals.FilterNameBy)this.cboName.SelectedValue;

    objSearchInfo.GroupId = (int)cboGroup.SelectedValue;
    objSearchInfo.Name = txtName.Text.Trim();
    if(chkFrom.Checked)
    objSearchInfo.FromDate = datefrom.Value;
    if(chkTo.Checked)
    objSearchInfo.ToDate = dateto.Value;

    objSearchInfo.SortBy = (rdoasc.Checked) ? Globals.SortBy.Asc : Globals.SortBy.Desc;
    objSearchInfo.SortByBirthDate = chkbirthdate.Checked; ;
    objSearchInfo.SortByGroup = chkGroup.Checked;
    objSearchInfo.SortByName = chkName.Checked;
    objSearchInfo.SortByTele = chkTele.Checked;

    objSearchInfo.TeleNumber = txtTeleNumber.Text.Trim();
    objSearchInfo.TelephoneType = (Globals.TelephoneTypes)this.cboTeleTypes.SelectedValue;

    // get result from bus logic layer
    PersonInfo[] objresult = Person.Find(objSearchInfo);


    image12.png

    image17.png

    How to save and retrieve image from database ?Save to database:

    save the image from the picturebox to MemoryStream and then save it on database as Byte[]
    // prapare the image
    if (null != imgperson.Image) // picturebox control
    {
    MemoryStream stream = new MemoryStream();
    imgperson.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
    info.Image = stream.ToArray();
    }

    Retrieve from database:
     // display the image
    byte[] PImage = info.Image;
    if (null != PImage)
    {
    MemoryStream stream = new MemoryStream(PImage);
    imgperson.Image = Image.FromStream(stream);
    }


    image18.png

    Restoring Database on SQL Server 2005


    Attach the database AhmedEid_PhoneBook.mdf from the directory DataBase on the root directory to the SQL Server Engine.

    Debugging Scenario


    Let us debug the advanced search button code to retrieve results with criteria from the client

    the following scenario will lead you to understand the Provider implementation

    make breakpoints as the following

    1- AdvancedSearch form class ( presentation layer )

    image19.png
    2- Person class of BusinessLogicLayer ( BLL layer )

    image20.png
    3- PersonProvider Class of DataAccessLayer ( DAL layer )

    image21.png

    4- InittMember<T> class of DataAccessLayer ( DAL layer )

    image22.png

    the above code will provide and add the SqlPersonProvider class to the providers list to be available for any usage.

    image24.png

    5- SqlGroupProvider class of DataAccesslayer ( DAL layer )

    image23.png


    Note: After debugging the code for 1st time , the providers (PersonProvider and groupProvider) will be added to the System.Configuration.Provider.ProviderCollection and for 2nd time the results will be retrieved without instantiating the classes again.

    image25.png
    References
    -
    http://msdn.microsoft.com/en-us/library/ms972319.aspx
    -
    http://msdn.microsoft.com/en-us/library/ms972370.aspx
    - http://msdn.microsoft.com/en-us/library/ms978496.aspx
    -
    http://en.wikipedia.org/wiki/Design_Patterns
    -
    http://www.c-sharpcorner.com/UploadFile/webmaster3/ProviderPattern12242007184126PM/ProviderPattern.aspx


    here, I tried to describe the topic briefly so please don't hesitate to contact me for more information

    Thanks

  • Sunday, November 2, 2008

    Microsoft SQL Server 2005 Certification from Micrsoft

    Posted on/at 1:30 AM by Admin

    The last certification from microsoft is :

    Microsoft SQL Server 2005 Implementation and Maintainance 



    About Me

    Developers house is a blog for posting technical articles in different technology like Microsft, Java, Oracle ..etc Microsoft technology includes c#,VB.net,ASP.net,Ajax,SilverLight,TFS,VS.NET 2003,2005,2008,2010 , SQL Server 2000, 2005 , Expression Blend , ...etc I hope it is helpful for all of you and if you are interested to post articles on it, only send me at ahmad.eed@gmail.com