Monday, January 28, 2013

Code : MS SQL vs MYSQL through adapters

It has been a very long time since I changed from Access to using MS SQL, so I decided to go for some thing new for my new apps and sites (none public so far), my choice went to MYSQL, not because it is just free with all features, but because when we go for small hosting plans for mid size sites and apps the chances are that you get more number of databases, bigger database size with MYSQL rather than MS SQL.

MS SQL connectors come by default with Visual Studios however MYSQL Connectors need to be installed and they are freely available at MySQL.

If we are used to using the MS SQL (SQLCE) data adapters style programming then MYSQL is also the same way of programming. Following is a small code portion from my project to show the difference between the SQLCE Adapter and the MYSQL adapter based programming:

Code with MS SQL CE adapter:

Dim Con As SqlCeConnection = New SqlCeConnection(DataSource)
Dim Cmd As SqlCeCommand
Cmd = New SqlCeCommand("INSERT INTO [commentstable]([PageID],[ParentID],[CommentID],[Comment],[CommentTime],[UserName],[UserEmail],[IsApproved]) VALUES (@PageID,@ParentID,@CommentID,@Comment,@CommentTime,@UserName,@UserEmail,@IsApproved)", Con)
Cmd.Parameters.Add(New SqlCeParameter("@PageID", SqlDbType.int))
Cmd.Parameters.Add(New SqlCeParameter("@ParentID", SqlDbType.int))
Cmd.Parameters.Add(New SqlCeParameter("@CommentID", SqlDbType.int))
Cmd.Parameters.Add(New SqlCeParameter("@Comment", SqlDbType.string))
Cmd.Parameters.Add(New SqlCeParameter("@CommentTime", SqlDbType.DateTime2))
Cmd.Parameters.Add(New SqlCeParameter("@UserName", SqlDbType.string))
Cmd.Parameters.Add(New SqlCeParameter("@UserEmail", SqlDbType.string))
Cmd.Parameters.Add(New SqlCeParameter("@IsApproved", SqlDbType.Boolean))
With SomeInsertObject
     Cmd.Parameters("@PageID").Value = .PageID
     Cmd.Parameters("@ParentID").Value = .ParentID
     Cmd.Parameters("@CommentID").Value = .CommentID
     Cmd.Parameters("@Comment").Value = .Comment
     Cmd.Parameters("@CommentTime").Value = .CommentTime
     Cmd.Parameters("@UserName").Value = .UserName
     Cmd.Parameters("@UserEmail").Value = .UserEmail
     Cmd.Parameters("@IsApproved").Value = .IsApproved
End With
If Con.State = System.Data.ConnectionState.Closed Then Con.Open()
Cmd.ExecuteNonQuery()
Con.Close()

Code with the MYSQL CE Adapter:

Dim Con As MySqlConnection = New MySqlConnection(DataSource)

Dim Cmd As MySqlCommand

Cmd = New MySqlCommand("INSERT INTO [commentstable]([PageID],[ParentID],[CommentID],[Comment],[CommentTime],[UserName],[UserEmail],[IsApproved]) VALUES (@PageID,@ParentID,@CommentID,@Comment,@CommentTime,@UserName,@UserEmail,@IsApproved)", Con)

Cmd.Parameters.Add(New MySqlParameter("@PageID", SqlDbType.Int))
Cmd.Parameters.Add(New MySqlParameter("@ParentID", SqlDbType.Int))
Cmd.Parameters.Add(New MySqlParameter("@CommentID", SqlDbType.Int))
Cmd.Parameters.Add(New MySqlParameter("@Comment", SqlDbType.VarChar))
Cmd.Parameters.Add(New MySqlParameter("@CommentTime", SqlDbType.DateTime2))
Cmd.Parameters.Add(New MySqlParameter("@UserName", SqlDbType.VarChar))
Cmd.Parameters.Add(New MySqlParameter("@UserEmail", SqlDbType.VarChar))
Cmd.Parameters.Add(New MySqlParameter("@IsApproved", SqlDbType.TinyInt))
            With SomeInsertObject
                Cmd.Parameters("@PageID").Value = .PageID
                Cmd.Parameters("@ParentID").Value = .ParentID
                Cmd.Parameters("@CommentID").Value = .CommentID
                Cmd.Parameters("@Comment").Value = .Comment
                Cmd.Parameters("@CommentTime").Value = .CommentTime
                Cmd.Parameters("@UserName").Value = .UserName
                Cmd.Parameters("@UserEmail").Value = .UserEmail
                Cmd.Parameters("@IsApproved").Value = .IsApproved
            End With
If Con.State = System.Data.ConnectionState.Closed Then Con.Open()
Cmd.ExecuteNonQuery()
Con.Close()

The only observable difference is that we need to change the name from SQLCE to MYSQL for code portion and some data types like string to varchar etc.

ComparedCode

Friday, January 11, 2013

SSD or Disk based HDD – What to buy?

I was planning in going for a SSD, but thought of checking if it is actually faster than the standard disk based Hard disks, with some cost limits in mind.   After thorough search and research on net, I came to know that SSDs are only preferred if more read speed is desired.

My current Hard Disk is 7200.11 16mb cache Seagate Hard Disk and following are the speeds I get from it:

My HDD Speed

However, from research,  the came to a conclusion that I might get double read speed from SSD to that of 7200rpms.

So, alternative is to get 32MB cache hard disks or go for 10000RPM hard drives, SSDs are to be developed to be made economical.

if space with speed is a concern then:

For Gain in Read speed use any Raid version 0,1,5,10,01

If Top write speed is must then use Raid 0

For Good write speed and safety etc use Raid 5,10,01

The disk speed measuring software can be downloaded from here.

Thursday, January 3, 2013

What a College Sir Ji

Below are only my personal views and are not intended for any assessment or hurting any others feelings….Read at your on discretion.

I don’t know what to say, but in short, look at this JOB POST, by a MBA (HR, Marketing, Finance etc.) teaching college which was thought to be great and well reputed college in Vizag and surroundings posted in search for “A candidate suitable for a marketing job”; with a twist asking for ‘1-3 year’ of experience in marketing; I don’t blame them for the post Nyah-Nyah; if the college could not teach and select its students for a Marketing job, with a discount of 1-3 year experience for ITS OWN SELF, how can the companies expect to recruit from such a college and I don’t want to talk more on its internal status.

They need candidates with MIS activities but let me tell you, there is NO MIS or any good excel DB/Storage of data for the MBA department when I studied in the collegeWinking smile.

I pray for a good future for its students (me included).

554303_550205908323927_1891314236_n

Tuesday, January 1, 2013

How to use Dot Net Appropriately?

Well this post is intended to starters only like me, even I am a newbie programmer, but I learned/learning lot of new things in how to use .net appropriately, firstly, we need a few things in clarification:

  1. Dot Net is only a library, like how we write our own classes, Microsoft Dot Net Team has written many strongly typed and well designed and managed code libraries.
  2. Instead of each developer creating a code library for his own very task, in which way every developer maintains his/her code library, Microsoft created and maintained a General/yet specific code library which covers mostly all sort of functions. Example:I have a library for string comparer, but every developer used to have the same, Microsoft gave this functionality  in Dot Net library and made it common for all with well typed name.
  3. All soft of Microsoft developed technologies can take use of this, as the library supports VB, C#, F#, C++ and even scripting can take advantage of this like POWERSHELL.
  4. Developer need not include old Dot Net in his installer as basic versions/old versions come preinstalled in windows systems.

When it come to using .NET appropriately, it means, first search if the functionality we need is there/existing in .Net library; for example:

We want to create a code for making sure the object is backed before editing, then saved or discarded based on user wish to save changes, instead of using our own desired names for Method/Functions, >NET gives this features with its own managed library names, and for reference, this functionality is supported by IEditableObjectInterface under System.Components Namespace, more information can be found at MSDN.

Making use of Inheritance and Implements are the greatest methods to follow for any .NET programmer.

All the code libraries in .NET are based on this methods only, like WPF implements INotifyPropertyChanged, and many classes are inherited from base classes.

First thing to do is try to give a read of what Interfaces are given in .NET, mostly the ComponentModel Namespace should do for generic purposes.

HAPPY NEW YEAR 2013 Smile