November 2, 2008

One thing you cannot achieve using command prompt but Windows PowerShell

I found it is not so special to run vbs (Visual Basic Script) in Windows PowerShell because most of the time you can do that using cscript with command prompt (cmd.exe).

But what I guarantee you cannot do is to change directory to a remote machine using command prompt for example,  as can see from the picture below I have a machine with IP address 192.168.1.26 so I can change the directory to c root of this machine by cd \\192.168.1.26\c$. I can perform other file operation directly in the remote machine such as make directory, copy file(s), delete directory and more.

In the past in order to manipulate files in between two or more machines you might need to map a network drive with a local drive letter. Windows Powershell gives me a better way to do this today.

powershell

In order to get to know more about Windows PowerShell go to script center :http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx.

Please feedback if you have other tips.

October 25, 2008

Write a simple object to and from XML using C#


Write a simple object to and from XML using C#

Write to XML file is always easier than read from XML file. Not too sure what I mean, it is alright because I have a sample for you to understand and comment.

In this sample I have a class BankAccount. I will serialize the BankAccount object to XML with 2 properties and use XMLReader to get back what have been written to the XML file (in the sample the file name for XML file is XMLBank.xml).

For this sample I glue the WriteXML and ReadXML method with the BankAccount. The entire class as below: 

public class BankAccount

  {

    public String AccID { get; set; }

    public double Amount { get; set; }

 

    public void WriteXML()

    {

      XmlSerializer serializer;

      TextWriter writer = new StreamWriter("XMLBank.xml");

 

      BankAccount bc = new BankAccount();

      bc.AccID = "13-0001";

      bc.Amount = 1000000;

 

      serializer =  new XmlSerializer(typeof(BankAccount));

      serializer.Serialize(writer, bc);

      writer.Close();

    }

 

    public void ReadXML()

    {

      XmlReader reader = XmlReader.Create("XMLBank.xml");

 

      reader.Read();

      reader.ReadStartElement("BankAccount");

      reader.ReadStartElement("AccID");

      Console.WriteLine(reader.ReadString());

      reader.ReadToFollowing("Amount");

      Console.WriteLine(reader.ReadString());

    }

  }

Doing it this way then the application will not tie down to any database such as Oracle Database or MS SQL.  If you have better and easier link then do share with me.

The complete code is in http://skydrive.live.com. The sample file name is ConsoleObjtoXML.rar. My MSN ID is chanmmn@hotmail.com.


Resources:


A Beginner's Guide to the XML DOM


XML Technology Center

October 19, 2008

The myth of LINQ (simplest sample for ADO.NET Entity Data Model)


If you are a .NET fan out there then you will basically hearing from many people asking, I have ADO.NET 2.0 so why is there a LINQ? It was a myth to me too. After Microsoft launch Service Pack 1 for Visual Studio 2008 then I clear some of my cloud in my head.

I will only mention one of the unique features here, ADO.NET Entity Data Model from ADO.NET Entity Framework. I have not found a better way to bind the Entity Model to DataGridView web control.

In order to create ADO.NET Entity Data Model, right click either Windows Application Project or Web Application Project and choose Add New Item… . Select ADO.NET Entity Data Model from the Add New Item dialog. After that you will have a file with edmx extension.

I have created a complete Windows Application sample using Northwind database in MS SQL 2008 Express. The Entity named NorthwindEntities. The entire sample consisted of 2 controls, 1 DataGridView and another is Button. I only have few lines of code in Button click event as below.

 private void btnGetCustomers_Click(object sender, EventArgs e)

{

  NorthwindEntities nwe = new NorthwindEntities();

 

  var cus = from customer in nwe.Customers

            select customer;

 

  dataGridView1.DataSource = cus;

}

I guess no one will ever say this is difficult.

The complete code is in http://skydrive.live.com. The sample file name is WinAppEntities.rar. My MSN ID is chanmmn@hotmail.com.


Unfortunately, ADO.NET Entity Data Model is not working with Oracle Database yet.

October 12, 2008

Write Table content from Database to XML file


I found the easiest way to write a table or even tables from database to XML file is in.NET languages. To do this in Java you might probably need to include not only one but few proprietary library or open source jar file.

 

To do this in C#, one of the .NET languages, there is no additional reference need to be added to the project. Only using System.Data is needed because of the Dataset.

 

The code segment that writes dataset to XML file as follow (the code segment is from MSDN library):

 

    static void WriteXmlToFile(DataSet thisDataSet)

    {

      if (thisDataSet == null) { return; }

 

      // Create a file name to write to.

      string filename = "XmlDoc.xml";

 

      // Create the FileStream to write with.

      System.IO.FileStream stream = new System.IO.FileStream

          (filename, System.IO.FileMode.Create);

 

      // Write to the file with the WriteXml method.

      thisDataSet.WriteXml(stream);

}

 

The complete code to extract the data from employee table of HR schema to XML from is in http://skydrive.live.com. The sample file name is ConsoleDatasettoXML .zip. My MSN ID is chanmmn@hotmail.com.

October 10, 2008

Larry @ Zdnet

It is about new HP server and storage technology with Oracle Database. It goes up to Exabyte space to cope with the information world today.

Oracle shows off new Exadata storage server
http://news.zdnet.com/2422-13568_22-236913.html

Oracle CEO launches 'world's fastest database machine
http://news.zdnet.com/2422-13568_22-236911.html

September 28, 2008

Oracle.DataAccess.dll in Windows Server 2008 x64

After I installed ODP.NET 11g ODTwithODAC1110621.zip in Windows Server 2008 x64 I got the following error message:
Could not load file or assembly 'Oracle.DataAccess, Version=2.111.6.20, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. An attempt was made to load a program with an incorrect format. (http://forums.oracle.com/forums/thread.jspa?messageID=2732111)

So, I changed the ODP.NET 10g ODTwithODAC10202.exe. Well, there was no luck and I was still getting the same error message from Visual Studio 2008.

Thanks to Mark William answered my question in the forum http://forums.oracle.com/forums/thread.jspa?threadID=706071&tstart=0.

Finally, Oracle.DataAccess.dll is able to open the connection to connect to Oracle Database 11g without an error. At the same time can create Data Sources without error too.

Somehow, in order to do that, I need to install both Oracle Client for Windows Server 2008 x64 and Oracle Client for Windows Server 2008 x86 download from the following link:
http://www.oracle.com/technology/software/products/database/index.html

September 20, 2008

Using ADF Business Components with Oracle ADF (end product)

ADF Business Component can test like a Windows Form application and pretty easy to build. The developer can deploy it for product too.

This is the end product of a demo instead of tutorial. If you are watching the viewlet Using ADF Business Components with Oracle ADF as the link http://www.oracle.com/technology/products/jdev/viewlets/1013/ADF_Business_Components_viewlet_swf.html and intend to have a complete sample to play with.

Download the sample file from http://skydrive.live.com. The sample file name is ADFBusinessComponent .zip. My MSN ID is chanmmn@hotmail.com

September 17, 2008

ODP.NET with Visual C++ 2008


Many developers still using C++ for some reasons. One of my customers is using VC++ but with open source database and he is not that happy with the database so he wants to change to Oracle database. This is a simple sample that I build for him with 1 button and 1 listbox.

When I was doing few lines of code for this sample I realize 2 not quite happy scenario in VC++; 1. The Oracle DataAccess Class does not appear in blue for example, OracleConnection, as compare to C#. 2. The intellisense is not as strong when comparing to C# as well.

The following are the few lines of code that in the sample:

static String ^ORA_CONNECTION_STRING = "Data Source=orcldemo;Persist Security Info=True;User ID=HR;Password=hr;";

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {

       OracleConnection ^conn = gcnew OracleConnection(ORA_CONNECTION_STRING);

       conn->Open();

 

       OracleCommand ^cmd = gcnew OracleCommand();

       cmd->Connection = conn;

 

       cmd->CommandText = "select department_id, department_name, city"

                + " from departments d, locations l" + " where d.location_id =

                   l.location_id";

 

        OracleDataReader ^dr = cmd->ExecuteReader();

 

       while (dr->Read())

       {

         listBox1->Items->Add("The " + dr->GetString(1) +

                           " department is in " + dr->GetString(2));

       }

 

       conn->Close();      

     }

 

Download the sample file from http://skydrive.live.com. The sample file name is WinAppCpp.zip. My MSN ID is chanmmn@hotmail.com

September 16, 2008

Build a Web Application with JDeveloper 10g Using EJB, JPA, and JavaServer Faces (end product)

If you are trying the tutorial from the link: http://www.oracle.com/technology/obe/obe1013jdev/10131/ejb_and_jpa/master-detail_pagewith_ejb.htm

Another short blog, tomorrow I will go for end product of viewlet instead of tutorial. If you are the one not too sure what viewlet is then please visit: http://www.oracle.com/technology/products/jdev/viewlets/viewlet.html.

After this tutorial you will realize you have not been doing much code by yourself, cool stuffs.

At the same time you feel like to have a complete sample to play with then download the sample file from http://skydrive.live.com. The sample file name is HR_EJB_App.zip. My MSN ID is chanmmn@hotmail.com

Do feedback to me if the end product does not run for you. Good day

September 15, 2008

Introduction to JavaServer Faces using JDeveloper (end product)

This one I did it back in May and should be fine. If you are trying the tutorial from the link: http://www.oracle.com/technology/obe/obe1013jdev/10131/jsfintro/jsfintro.htm

This tutorial is the good one to pick up Java Server Face (jsf). The fact is most of the developers build web pages in Java technology will use jsf.

At the same time you feel like to have a complete sample to play with then download the sample file from http://skydrive.live.com. The sample file name is JSFIntro.zip. My MSN ID is chanmmn@hotmail.com

Do feedback to me if the end product does not run for you. Have fun.