Responsive Ads Here

Friday, October 6, 2017

Data Table to XML Genrate


 ///





      /// Write out XML to a DataTable to a file in a controlled manner.
      /// Use a XmlWriterSettings to control the output formatting.
      ///
      public static string DataTableToXML(DataTable table)
      {
         XmlWriterSettings settings = new XmlWriterSettings();
         settings.CheckCharacters = true;
         settings.CloseOutput = true;
         settings.ConformanceLevel = ConformanceLevel.Document;
         settings.Encoding = Encoding.UTF8;
         settings.Indent = false;
         settings.NewLineHandling = NewLineHandling.Replace;
         settings.NewLineOnAttributes = true;
         settings.OmitXmlDeclaration = true;

         using (var sw = new StringWriter())
         {
            using (var writer = XmlWriter.Create(sw))
            {
               // Build Xml with xw.
               writer.WriteStartDocument(true);
               WriteTable(writer, table);
               writer.WriteEndDocument();
            }
            return sw.ToString();
         }
      }

      private static void WriteTable(XmlWriter writer, DataTable table)
      {
         //     
         writer.WriteStartElement("DocumentElement");

         foreach (DataRow row in table.Rows)
         {
            //

            writer.WriteStartElement(table.TableName);

            foreach (DataColumn column in table.Columns)
            {
               writer.WriteStartElement(column.ColumnName);
               writer.WriteValue(row[column].ToString());
               writer.WriteEndElement();
            }
            //
            writer.WriteEndElement();

         }

         //
             writer.WriteEndElement();
      }

Tuesday, September 26, 2017

XML Helper for convert class object/List to xml and xml to class object/List conversion


Hi friend's, today we are going to understand ubout XMl Helper for convert class object/List to xml and xml to class object/List convertion.

let's start with example,

Create class for EmployeeDetail


public class EmployeeDetails
    {
        [XmlAttribute]
        public int EmployeeID { get; set; }
        [XmlAttribute]
        public string EmployeeName { get; set; }
        [XmlAttribute]
        public string EmailID { get; set; }
        [XmlAttribute]
        public List lstEmployeeDetails { get; set; }
    }
Now, we have one class XMLHandler that contains two methods that make our work easy and clean.
  • Method ConvertToXML for Generic code to convert Xml to class object or list.
  • Method Convert for Generic code to convert class object or list to Xml.
public static class XMLHandler
    {
        public static T Convert(string inputString)
        {
              XmlSerializer serializer = new XmlSerializer(typeof(T), string.Empty);
MemoryStream memStream = new MemoryStream(Encoding.UTF8.GetBytes(inputString));
              T resultingMessage = (T)(serializer.Deserialize(memStream));
              return resultingMessage;
        }
        public static string ConvertToXML(T obj)
        {
            if (obj == null)
            {
                return string.Empty;
            }
            XmlSerializer serializer = new XmlSerializer(typeof(T));
            StringWriter sww = new StringWriter();
            using (XmlWriter writer = XmlWriter.Create(sww))
            {
                serializer.Serialize(writer, obj);
                return sww.ToString().Replace("", "").Replace(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"", ""); // Your XML
            }
        }
    }

To convert List to xml:
Now we will create instance for EmployeeDetails
EmployeeDetails objEmployeeDetails = new EmployeeDetails();
string xml = XMLHandler>.ConvertToXML(objEmployeeDetails. lstEmployeeDetails);
It will return xml as below Figure,



So, that's all guys i hope these will help you to create xml using object/class.
please share this blog if this helpful you. https://dotnetupdatedtechnology.blogspot.com/

Thursday, September 21, 2017

Improve SQL Query Performance

Hi friend's, today we are going to understand step to improve t-sql query perfomance step by step mention below.

  1. Use EXISTS instead of IN to check existence of data.
  2. Avoid * in SELECT statement. Give the name of columns which you require.
  3. Choose appropriate Data Type. E.g. To store strings use varchar in place of text data type. Use text data type, whenever you need to store large data (more than 8000 characters).
  4. Avoid nchar and nvarchar if possible since both the data types takes just double memory as char and varchar.
  5. Avoid NULL in fixed-length field. In case of requirement of NULL, use variable-length (varchar) field that takes less space for NULL.
  6. Avoid Having Clause. Having clause is required if you further wish to filter the result of an aggregations.
  7. Create Clustered and Non-Clustered Indexes.
  8. Keep clustered index small since the fields used in clustered index may also used in non-clustered index.
  9. Most selective columns should be placed leftmost in the key of a non-clustered index.
  10. Drop unused Indexes.
  11. Better to create indexes on columns that have integer values instead of characters. Integer values use less overhead than character values.
  12. Use joins instead of sub-queries.
  13. Use WHERE expressions to limit the size of result tables that are created with joins.
  14. Use TABLOCKX while inserting into a table and TABLOCK while merging.
  15. Use WITH (NOLOCK) while querying the data from any table.
  16. Use SET NOCOUNT ON and use TRY- CATCH to avoid deadlock condition.
  17. Avoid Cursors since cursor are very slow in performance.
  18. Use Table variable in place of Temp table. Use of Temp tables required interaction with TempDb database which is a time taking task.
  19. Use UNION ALL in place of UNION if possible.
  20. Use Schema name before SQL objects name.
  21. Use Stored Procedure for frequently used data and more complex queries.
  22. Keep transaction as small as possible since transaction lock the processing tables data and may results into deadlocks.
  23. Avoid prefix “sp_” with user defined stored procedure name because SQL server first search the user defined procedure in the master database and after that in the current session database.
  24. Avoid use of Non-correlated Scalar Sub Query. Use this query as a separate query instead of part of the main query and store the output in a variable, which can be referred to in the main query or later part of the batch.
  25. Avoid Multi-statement Table Valued Functions (TVFs). Multi-statement TVFs are more costly than inline TVFs.
So, that's all guys i hope these will help you to easy understand this post.

Wednesday, September 13, 2017

How to make Visualization Report Using Power BI?

How to use  Power BI Desktop Tool?

  • First we need to Sign up/ Register on Power BI
Fig 1.0


  • For make any Visualization we need some data for visualize through Power BI
    • To get data  go through following step
      • Home Tab --> Get Data
      • Select Data source type which we want to add or use data for our visualization
As shown in below screenshot
Fig 2.0
As shown in above figure there are many types of data sources available.

  • In our example we use SQL Server Database by clicking SQL Server database from list and Click on Connect.
  • By clicking Connect  it prompts a window for Server and database for import data.
  • Enter Server name and Database name and click OK.
  • After Clicking OK, there are one more prompt window “Navigator” which lists the  database objects
  • As shown in above Fig 2.0, select  database objects which we want to use our report, after choosing db objects click on Load.
  • we find selected db objects at right side under  "Fields" pane as shown in Fig 3.0.
Fig 3.0
  • There are wide range of  visualizations available here.Using these Visualizations  we can build reports as our need.
For an example we are going to make report  of sales by category.

As shown in below Fig 4.0, Take a Pie chart  from visualizations grid.

Fig 4.0

  • Now just Drag and Drop the Column or Field from Fields section.
  • We take "CategoryName"  into Legend  and  "ProductSales" into  Values field.
There are many other features are also provided there like
  • Tooltips
  • Filters
  • Details
  • Page level filters
  • Report level filters
There are also Format tab of your report  from using that you can format  your report as per your need.
Fig 5.0
There are options to customize your report like
  • Legend – set legend text, color size and position
  • Data colors – customize data colors
  • Details Labels
  • Title
  • Background 
  • Lock aspect
  • General – set position, width and height of report
  • Border 
You can find the data by clicking Data  Tab  on left side as shown in figure. Also column formatting, adding also available here in data tab.
Fig 6.0
You can also find and manage relationship among db objects or data objects  under "Relationships Tab"  as shown in  below Fig 7.0.
Fig 7.0
Under Relationships Tab, we can easily manage relationships among data objects. We can edit, add or delete relationships  here as shown in above Fig 7.0.
  • After making report  you can publish this report to Power BI
  • Now, publish report to web using following steps
  • File Menu   -->   Publish  --> Publish to Power BI
  • After publishing successfully  go to your PowerBI account
  • You can find the report under "Report Section" on left side menu and Dataset under "Dataset Section".
Hope, This will help you.
Thank You.

SSMS Formatter use with Microsoft SQL Server Management Studio 2016

Hi friend's, today we are going to understand that how to apply Format for your query in SSMS(Microsoft SQL Server Management Studio 2016).
You just need to go through some steps that mentioned below.
  1. First start the SQL Server (SSMS 2016)
  2. On the top of the Menu --> Tools --> Options


Fig 1.0

After open the Options pop up on left side shown the menu.

  3. Environment --> Keyboard --> under the Show Commands containing.

Fig 2.0

  4. SSMSBoost.Format --> select Use new shortcut in: --> Text Editor --> Press shortcuts keys: Ctrl + k, Ctrl + D --> Click On 'Assign' and then Click 'OK'.
  5. All set to format your Query. Now just write query and apply you Short Cut key.


Hope, This will help you.Thank You.

Tuesday, August 29, 2017

 Steps For Creating MSMQ Support Application


Hi friend's, today we are going to understand ubout MSMQ(Microsoft Message Queuing) and how will setup/configure MSMQ in our local machine.

Now first try to understand about MSMQ.

  1. What is MSMQ?
  2. How Does it Configure in local machine?

1. What is a MSMQ?

MSMQ is stand for Microsoft Message Queuing. Message Queuing is a message infrastructure and a development platform for creating distributed messaging applications for the Microsoft Windows Operating System.Message Queuing is a part of the Windows Operating System.
  • There are different types of Message Queues:
    • Normal Message
    • Acknowledgement Message
    • Respond Message
    • Report Message

2. How Does it Configure in local machine?

Hear mention step by step configure message queue in local machine.
  1. Turn On following Windows Features
  2. Create WCF Service
  3. Config in IIS Server
  4. Manage and Config MSMQ
  5. Open Web Config of WCF Service
  6. Add Binding for it under serviceModel
  7. Add services Attribute in serviceModel
  8. After Completion all above mention step check our service is running  or not

2.1. Turn On following Windows Features

  • Windows Communication Foundation Non-HTTP Activation under .Net Framework 3.5.
  • If we have .Net Framework 4.6 Advanced Services feature then all the features under it.
  • All the features under Internet Information System and Internet Information System Hostable web core.
  • All the features under Microsoft Message Queue Server.
  • All the features under Windows Process Activation Services.
  • As Shown in screenshot.
Fig 1.1

2.2. Create WCF Service

  • Open Visual Studio
  • Create New Project
  • WCF Service Application
  • Give Name and folder location and create
  • Right click on Service.svc
  • Click on View Mark Up

2.3. Config in IIS Server

  • Start > Internet Information Service (IIS) Manager.
  • Right click on Application Pool > Add Application Pool > give name same as your Project name so it will easy to map as shown in fig 3.1.

Fig 3.1
  • Right click on Application Pool > Add Application Pool > give name same as your Project name so it will easy to map as shown in fig 3.1.
  • Right Click on Default Web Site under Sites and Add application > give alias same as your project name > and then select application Pool which you created as shown in fig 3.2.
Fig 3.2
  • Right Click on Default Web Site under Sites and Add application > give alias same as your project name > and then select application Pool which you created as shown in fig 3.2 and browse for your project in physical path and save it.
  • Right click on created site DataPushWCFService> Manage Application> Advance Settings > Enable protocols = http,net.msmq.

2.4. Manage and Config MSMQ

  • Right click on My Computer > Manage > Expand Services and Applications> Expand message Queue > Right Click on Private Queues > New > Private Queue.
Fig 4.1
  • Right click on DataPushWCFService private queue.
  • Properties > Click on Security Tab > add new group or user names > add “IIS APPPOOL\DataPushWCFService” without double quotes in that DataPushWCFService is same name as site in application pool and allow all permissions in that and other users also.

2.5. Open Web Config of WCF Service



  • Go to system.serviceModel
  • Into Service Behaviour there will be one default behavior, add name for that default behaviours. If you need more than one behavior then you can add more than one behaviour as per your requirement as shown in following image and change includeExceptionDetailInFaults to true.



Fig 5.1

2.6. Add Binding for it under ServiceModel


  • Add Bindings Attribute in it
  • In that add .netMsmqBinding attribute as shown below image.
Fig 6.1

2.7. Add services Attribute in ServiceModel

  • Add services Attribute in serviceModel
  • Add Service in that Services attribute with endpoints as shown below.
Fig 7.1
In that name with WcfDemoApp should be your project name and Service1 should be your Service name and add bindingConfiguration will be which you created for it as shown in fig 7.1, add endpoints as shown in fig 7.1 in that Address should be your private queue name as shown in fig 7.1 and bindingConfiguration which you created with name No Security Under Binding attribute of ServiceModel.

2.8. After Completion all above mention step check our service is running  or not

  • After completion of this all steps to check our service is running or not > Open IIS >Click on your Web site> Select yourService.svc file> click on Browse, If it not showing any error then its working fine now code to retrieve or consume this WCF Service, Copy its URL.


2.9. Some known Issues and solutions



  • Create one console Application > Create New Project > Console Application >Browse Folder path > Create > right click on references > Add service reference > give URL which you copied in previous step and add it.

Some known Issues and solutions:

  1. The protocol 'net.msmq' is not supported.
  2. The protocol 'net.tcp' is not supported.
  3. The protocol 'net.formatename' is not supported.
  4. The protocol 'net.pipe' is not supported.

Solution For solution right click on default web site > Edit Binding > and add net.msmq at localhost, net.tcp at 808:*, net.formatename at localhost and net.pipe at * as shown in below fig 9.1.

Fig 9.1.


   5. The requested content appears to be script and will not be served by the static file handler.
Solution: 

  • cmd -> Right click -> Run as administrator
  • cdC:\Windows\Microsoft.NET\Framework\v4.0.30319
  • aspnet_regiis.exe -i.

So, that's all guys i hope these will you to understand msmq and work easy with msmq. 

 Step By Step Process To Upload Document In Azure Blob Storage Using .NET


Hi friend's, today we are going to understand how to upload document in azure blob storage. i read many blogs and articals about this but i couldn't find any useful blog for this or provided proper information about blob. i collect many information about azure blob and want to share with you. i hope it is useful for you.


Now first try to understand about azure blob.


  1. What is a blob Storage?
  2. Blob Service Concepts
  3. Create an Azure Storage Account
  4. Create a project in visual studio
  5. Install client library & Azure Configuration manager using nuget packages
  6. Code Upload a Image into a container

1. What Is a Blob Storage?

Azure blob Storage is a provide service, large amount of unstructured data in binary or text format.That can accessed from any where using HTTP or HTTPS.

Common use of blob storage:
  • Using blob, image or documents upload directly to browser 
  • Using blob, Uploading video or audio
  • Storing data for backup and restore 
  • Storing data for analysis by an on-premises or Azure-hosted service
2. Blob Service Concepts
  • Storage Account: Storage Account is done through azure access storage account. General-purpose storage account or a Blob storage account which is specialised for storing objects/blobs. please check for more information About Azure Storage Account.
  • Container: Container provider grouping of a set of blobs. an account can contains number of containers.NOTE: The container name must be an small lovercase.
  • Blob: Hear Microsoft describe different type of blob mention below. 
    • Block Blobs: Are Storing text or binary file, such as media files.
    • Page Blobs: can more efficient to read/write orations.Azure Virtual Machines use page blobs as OS and data disks.
    • Append Blobs: Are similar to block blob type
3. Create an Azure Storage Account
4. Create Project in Visual Studio

In Visual Studio, Create an Console application or project first.hear i create console application.
  1.  Select File > New > Project 
  2. Select Installed > Templates > Visual C# > Windows Classic Desktop
  3. Select Console App (.NET Framework)
  4. Enter a name for your application in the Name: field
  5. Select OK


5. Install client library & Azure Configuration manager using nuget packages

Hear two main package need to reference in your project.

  • Microsoft Storage Client Library for .Net:
    • In Visual Studio, Tool > NuGetPackage Manager > Package manager then use this command in command manager.
      • PM> Install-Package WindowsAzure.Storage -Version 8.4.0
  • Microsoft Azure Configuration Manager 
    • In Visual Studio, Tool > NuGetPackage Manager > Package manager then use this command in command manager.
      • PM>Install-Package Microsoft.WindowsAzure.ConfigurationManager -Version 3.2.3
6. Code Upload a Image into a container

  • Create one class file in created project like xxx.cs file.
  • Created this class file Create Static method.
Below mention .net c# code for upload image using block blob type blob storage


static void Main(string[] args)
{
    UploadImageInToBlobStorage();
}

//Class file method
public static void UploadImageInToBlobStorage()
{
// Block blob basics example
StartBlockBlobOperationsAsync().Wait();
}

private static async Task StartBlockBlobOperationsAsync()
{
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference("adftechnobrainsblob");

if (await cloudBlobContainer.CreateIfNotExistsAsync())
{
await cloudBlobContainer.SetPermissionsAsync(
new BlobContainerPermissions
{
PublicAccess = BlobContainerPublicAccessType.Blob
}
);
}

CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference("Image Name Hear");
cloudBlockBlob.Properties.ContentType = filetype;
//HttpPostedFileBase file object property use InputStream
await cloudBlockBlob.UploadFromStreamAsync(Image Stream hear);
}


In Web.config file, under the appSetting key 




So, that's all guys i hope These will you to understand basic of Azure blob upload document.
{ "@context": "http://schema.org", "@type": "Organization", "url": "http://c-sharpnets.blogspot.com/", "logo": "http://c-sharpnets.blogspot.com/images/logo.png" }