May222008

coding in my dreams?

i dont remember my dreams; no seriously i dont. I cant really say i dont dream while i am asleep, cause i dont remember if any :)

So, my wife; a few times told me that i talked to her when i was sleeping ;) probably i was dreaming. She told me yesterday i was telling her; "these benchmarks are very important for performance".  I have no idea what those benchmarks were, but it was a proof for me that i dream :), interesting that i dream about coding ; a few todays ago, my wife this time told me , i was talking about some algorithm.

I wish i could pop a usb memory in my ear (hey i said ear ok ? ), and record my dreams; that would be fun 



Tags:

E-mail | Permalink | Trackback | Post RSSRSS comment feed 1 Responses

May212008

disable debugging in ur server

Ok we all know we should change debug mode to false in our web config when it is time to upload the site to the server; and guess what, we might forget it right ?

I just learnt the easiest way :) of disabling debug to false in the web server. Go to machine.config file in the web server, find system.web section and add <deployment retail="true"/> 

is that it or what :) 



Tags:

E-mail | Permalink | Trackback | Post RSSRSS comment feed 0 Responses

May202008

I passed 70-431

i was studying for the MS 70-431 Implemantation and Administration Sql Server 2005 exam in the last 4 weeks, besides the projects @work, this kept me really busy. Even though i use sql server 2005 in work daily, you never what might microsoft ask you :), so i bough the ms press book for the exam, and went through each chapter,  and today i passed it :) 

Now as i didnt get the email from microsoft yet, i am not %100 sure about what certifications i will get by passing this exam, but according to microsoft's web site, i am now MCP, and MCTS. my next target is asp.net web development certification track, let see :)

 



Tags:

E-mail | Permalink | Trackback | Post RSSRSS comment feed 1 Responses

May182008

XML, Linq, GridView, Label

I had a very small project, where there would be page that lists events, another page that adds events. I didnt want to have a database for this simple pages, so i decided to go on with xml file. My xml file structure is basically like below: 


Now i need a pagethat will list all the events (hopefully ordering them according to When attribute which is a datetime. so i created a page put a label on the page, and open the code behind file.

What i want to do is, open the xml file, order them, and dump the data into the label, so i decided to use linq, as i am learning this new technique. Below is the simple code for this, linq made it so easy for me to parse the xml; unbelievable:

 


BTW you could do the exact same thing with xmldatasource and xpath, however; i am not sure with ordering :), ordering wont be that easy i guess with xmldatasource, here is the page that does the above listing with xmldatasource and gridview and xpath:

 



Tags:

E-mail | Permalink | Trackback | Post RSSRSS comment feed 2 Responses

May012008

Change DB Access to Interface

As i mentioned in my previous posting, i am trying to seperate the modules in my projects so i can test every single code. I am new to TDD so i meet a lot of challenges during the adoptation. One of them is the database access, how will i unit test a class or a function where these is a database dependency.  i decided to create a generic database access class, which implements an interface that could be mock out.

In the database side, i always use stored procedures to do actions, and my stored procedures either returns an integer value (if it doesnt return anything like delete from..., consider it returns 1),  or a DataTable such as select * from table. So i can easily write an interface such as:

[code:c#]
public interface IExecuteProcedure
    {
        DataTable GetDataTable(string StoredProcedureName, List<SqlParameter> Parameters);
        int ExecuteStoreProcedure(string StoredProcedureName, List<SqlParameter> Parameters);
    }
[/code]

So GetDataTable runs a stored procedure with a list of parameters given , and returns a DataTable, ExecuteStoreProcedure returns int.  A database access class could follow a pattern like below to implement this interface:

[code:c#]
public class DatabaseAccess:IExecuteProcedure
    {
        private readonly string ConnectionString_;

       
        public DatabaseAccess(string ConnectionString)
        {
            this.ConnectionString_ = ConnectionString;
        }
       
        public DataTable GetDataTable(string StoredProcedureName, List<SqlParameter> Parameters)
        {
            SqlConnection conn = new SqlConnection(ConnectionString_);
            SqlCommand cmd = new SqlCommand(StoredProcedureName, conn);
            cmd.CommandType = CommandType.StoredProcedure;
            foreach (SqlParameter param in Parameters)
            {
                cmd.Parameters.Add(param);
            }
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            try
            {
                da.Fill(dt);
            }
            catch (Exception)
            {
                dt.Clear();
            }

            return dt;
        }

        #region IExecuteProcedure Members

        public int ExecuteStoreProcedure(string StoredProcedureName, List<SqlParameter> Parameters)
        {
            SqlConnection conn = new SqlConnection(ConnectionString_);
            SqlCommand cmd = new SqlCommand(StoredProcedureName, conn);
            cmd.CommandType = CommandType.StoredProcedure;
            foreach (SqlParameter param in Parameters)
            {
                cmd.Parameters.Add(param);
            }
            int iReturn = 0;
            try
            {
                conn.Open();
                cmd.ExecuteScalar();

                for (int i = 0; i < Parameters.Count; i++)
                {
                    if (Parameters[i].Direction == ParameterDirection.Output)
                    {
                        Parameters[i].Value = cmd.Parameters[Parameters[i].ParameterName].Value;
                        iReturn = Int32.Parse(Parameters[i].Value.ToString());
                    }
                }
            }
            catch(Exception ex)
            {
                iReturn = Int32.MinValue;
            }
            finally
            {
                conn.Dispose();
            }
            return iReturn;
        }

        #endregion

       
    }
[/code]

So the database access class implements the interface, and returns the appropriate values. Now in my next posting we will see how we can use this class to access the database, but also we will see how we can inject some code, and change the behaviour without changing the structure.

 

 



Tags:

E-mail | Permalink | Trackback | Post RSSRSS comment feed 0 Responses