Saturday, April 30, 2011

Microsoft SQL Server, Error 14234

Lately,

I installed an SQL Server 2005 database on my clients server machine,and when i created a database maintenance plan,i got the error as stated:

The specified '@subsystem' is invalid (valid values are returned by sp_enum_sqlagent_subsystems). (Microsoft SQL Server, Error 14234)

The solution is to install SQL Server 2005 Integration Services.

Tuesday, April 26, 2011

"Installation Incomplete - The installer was interrupted before could be installed. (Visual Studio Web Setup Project)

Recently,the asp.net software i maintained crashed down and can't be opened by the browsers (IE,Firefox and chrome). I tried different kinds of solutions but they don't work. So,i tried the steps below to re-install the web setup package with the error provided as the title of the post.
Culprit: virus attack[dangerous or high risk worm/trojan]
Solution:
1. Repair windows xp sp2 (using installer cd) XP Repair Install
Note: I performed only steps 1-6
2. After repairing, I uninstalled the IIS
3. Delete the current Inetpub folder in Drive C:\ [make sure to backup any files in the Inetpub folder]
4. Then restart PC after performing steps 2-3
5. Re-install IIS using windows xp sp2 cd
6. Register asp.net 2.0 from command prompt
c:\windows\microsoft.net\framework\v2.0.50727>aspnet_regiis -i
7. Restart PC/Server
8. Continue Installing VS Web Setup Project

Note: This may also apply to Windows 2003 server or new Windows OS.

StringCollections in .NET

After some tiresome work, i decided to visit MSDN. Along the way,i manage to take a grip from System.Collections.Specialized StringCollection class.
I was used to List, ArrayList, and etc. After reading MSDN's documentation,I managed to create a simple example.
Code:
  class Program  
    {  
      static void Main(string[] args)  
      {  
        //defined class  
        StringCollections collections = new StringCollections();  
        //.NET collection class  
        StringCollection netcollection = new StringCollection();  
        string[] names = new string[5];  
        //insert five elements  
        for(int i = 0; i <5; i++)  
        {  
          names[i] = "nelson" + (i+1);  
        }  
        //store to stringcollection object  
        netcollection = collections.Employees(names);  
        //navigate collection class  
        StringEnumerator enumerator = netcollection.GetEnumerator();  
        while (enumerator.MoveNext())  
        {  
          Console.WriteLine(enumerator.Current);  
        }  
        Console.ReadLine();  
      }  
    }  
    internal sealed class StringCollections  
    {  
      public StringCollection Employees(string[] names)  
      {  
        StringCollection collections = new StringCollection();  
        try  
        {  
          collections.AddRange(names);  
        }  
        catch (Exception ex)  
        {          
          throw new Exception(ex.InnerException.Message);  
        }  
        return collections;  
      }  
    }  
The code above,will display the list using Enumerator. You could use foreach or other methods. But I decided the Enumerator object..
Cheers!!!

Sunday, April 24, 2011

ASP.NET MVC View Model

I recently read an article from Stephen Walther on View Models and gave it a spin. In this example,i created two typed class namely People and address..You may create properties or public fields in there. After that,create a controller with the view model which has List properties. Then in your view,you simply inherit the PersonViewModel.

Below is the Person Controller with the PersonViewModel.
Code:
  public class PersonController : Controller  
    {     
      public ActionResult Index()  
      {  
        // Create list of People  
        var people = new List<People>();  
        people.Add(new People(30, "Nelson G."));  
        people.Add(new People(28, "James Ingram"));  
        // Create list of Address  
        var address = new List<Address>();  
        address.Add(new Address(9000, "Cebu"));  
        address.Add(new Address(6521, "Baybay"));  
        // Return view  
        return View(new PersonViewModel(people, address));  
      }  
      public ActionResult Details()  
      {  
        // Create list of People  
        var people = new List<People>();  
        people.Add(new People(30, "Nelson G."));  
        people.Add(new People(28, "James Ingram"));  
        // Create list of Address  
        var address = new List<Address>();  
        address.Add(new Address(9000, "Cebu"));  
        address.Add(new Address(6521, "Baybay"));  
        // Return view  
        return View(new PersonViewModel(people, address));  
      }  
    }  
  // View Model Classes  
    public class PersonViewModel  
    {  
      public PersonViewModel(List<People> people, List<Address> address)  
      {  
        this.People = people;  
        this.Address = address;  
      }  
      public List<People> People { get; private set; }  
      public List<Address> Address { get; private set; }  
    } 
Here is the view that will utilize the PersonViewModel.
 <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"   
 Inherits="System.Web.Mvc.ViewPage<ViewModelsDemo.Controllers.PersonViewModel>" %>  
 <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">  
   Details  
 </asp:Content>  
 <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">  
   <h2>Details</h2>  
     <ul>  
       <%int i = 0; %>  
       <%foreach (var item in Model.People) %>  
       <%{ %>  
         <li> <%=item.Name %> &nbsp; <%= Model.Address[i].completeAdd %> </li>     
          <%i++; %>       
       <%} %>  
       </ul>  
 </asp:Content>  

Thursday, April 14, 2011

Accessing HttpUtility class in C# Winforms

To use HttpUtility class in C# winforms, do the following:
1. Add reference to System.Web dll
2. Use any methods available in HttpUtility class.
Code:
System.Web.HttpUtility.HtmlDecode(mystring);
System.Web.HttpUtility.UrlDecode(mystring);
Cheers!

Thursday, April 7, 2011

Using Sessions in .NET Web Services

Lately, i was confronted with a problem on managing state with web services, after reading a book on xml in .NET 2.0, i found a tip on creating and consuming web services with state capabilities.

I followed this link: Using Session State in a Webservice
MSDN: Web Service Session

This idea, is a life saver to some of my web projects.. :D

Visual C# 2010 Express (System.Web Namespace not found)

When you created a winforms project and you would like to use HttpUtilities or other classes found on System.Web, you might notice that when you tried adding reference to System.Web, it is not found on the .NET Tab.

By default, the project is targeted on .NET Compact framework 4.0, so just change it to .NET Framework 4.0. By then,you will be able to add the System.Web namespace in your projects.

Cheers