Monday, August 19, 2013

Create webservice to get custom xml structure

* Add below line of code to your service.cs , used three tier architecture and Commented out direct db call .


#region HeaderOfXml
    private StringBuilder CreateBaseStringBuilder()
    {
        StringBuilder BaseDocument = new StringBuilder();
        BaseDocument.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
        return (BaseDocument);
    }
    #endregion



    [WebMethod]
    public XmlDocument GetDealerList()
     {
         //  DataSet ds = new DataSet();
          //  SqlConnection cnn = new //SqlConnection(ConfigurationManager.ConnectionStrings["Connect"].ConnectionString);
    //    cnn.Open();
    //         SqlCommand mycommand = new SqlCommand("usp_testSp", cnn);
 //       mycommand.CommandType = CommandType.StoredProcedure;
  //      SqlDataAdapter adp = new SqlDataAdapter(mycommand);
  //      adp.Fill(ds);


        BusinessDealerList objBusiness = new BusinessDealerList();
        DataSet ds = objBusiness.GetDealerList();
        // ds = DealerCollection;
        EntityDealerList ObjEntity = new EntityDealerList();

        //DataSet ds1 = new DataSet();
        Document = CreateBaseStringBuilder();
        Document.AppendLine("<Dealer>");

//use for each to loop through each data
        foreach (DataRow dr in ds.Tables[0].Rows)
        {
            ObjEntity.Code = dr["Code"].ToString();
            ObjEntity.Name = dr["Name"].ToString();
            Document.AppendLine("<Dealer>");
            Document.AppendLine("<Code>" + ObjEntity.Code + "</Code>");
            Document.AppendLine("<Name>" + ObjEntity.Name + "</Name>");
            Document.AppendLine("</Dealer>");

        }
        Document.AppendLine("</Dealer>");
        XMLDocument.LoadXml(Document.ToString());


// Add this if you want to create an xml and write data in it
        // Save the document to a file 

        XmlTextWriter writer = new XmlTextWriter(@"C:\data.xml", null);
        writer.Formatting = Formatting.Indented;
        XMLDocument.Save(writer);

        return (XMLDocument);

    }


//inside webconfig add below 
 <connectionStrings>
    <remove name="LocalSqlServer" />

    <add name="
Connect" connectionString="data source=10.11.48.89;uid=sa;pwd=abcd;initial catalog=testDB" providerName="system.data.sqlclient"/>
   
  </connectionStrings>



Monday, August 12, 2013

The benefits of normalization


The two main benefits you get from normalization.
Benefit #1: Reduce data redundancy.
Unless absolutely necessary, storing redundant data is a waste of system resources. Nowadays hard disk space is cheap but is not free. More importantly, maintaining very large size of databases requires more work on database administrators and network engineers.
Benefit #2: Reduce data inconsistency.
The data redundancy issue can further cause date inconsistency issues. As we keep the same piece of data across different locations, we have to make sure that they are kept exactly the same all the time. For example, when one piece of data is updated, the same data in other locations has to be updated as well.
The issues of data inconsistency are collectively called Data Anomaly. There are four types of possible errors they could cause. These four types of errors are the causes of data anomaly:
Select anomaly (also known as join anomalies):
This happens when we select the same piece of data from different tables but they could produce different results.
Update anomalies
This occurs when we update the same piece of data in more than one place. If care not taken, we could end up with updating the data in one place but forgot to update it in another place.
Insertion anomalies
This can happen when we are adding a new record for the data. If we forgot to insert it to other places for the same data, data inconsistency occurs.
Deletion anomalies
This happens when we delete data. If the deletion does not remove the same data from all places, data anomalies occur.

ASP.NET MVC Execution Process







Introduction to MVC Architecture


MVC is an architectural pattern that splits interactions between users and applications into three roles:
* Model (business logic)
* View (user interface)
* Controller (user input) 
Model 
                 The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). 
      View
The view manages the display of information.
        Controller
The controller interprets the mouse and keyboard inputs from the user, informing the model and/or the view to change as appropriate. 
 
o Controller contains all Controller classes.
o Models contains all Models classes.
o Views contains associated views.
o Content contains all CSS / Images / other libraries
o Script contains default scripts loaded MVC