BEST ARCHITECTURE FOR LARGE APPLICATION


  • AZURE SERVICE FABRIC
  • AZURE CLOUD STORAGE
  • ASP.NET CORE
  • ANGULAR 4
  • HTML5
  • CSS3

You can download pdf file from HERE

SHRINK LOG File In MSSQL Server

THIS IS NOT A RECOMMENDED PRACTICE for production systems... You will lose your ability to recover.

Requires membership in the sysadmin fixed server role or the db_owner fixed database role.
Syntax
DBCC SHRINKFILE ([Logical log file name],target size in MB)
Example
-- Shrink the truncated log file to 1 MB.
USE STUDENT
DBCC SHRINKFILE (Student_log, 1);
GO

In this command some time log file size will be  not reduce because of Database recovery MODE is FULL, You need to set recovery mode as SIMPLE.
USE STUDENT
ALTER DATABASE STUDENT
SET RECOVERY SIMPLE;
GO
-- Shrink the truncated log file to 1 MB.
DBCC SHRINKFILE (Student_log, 1);
GO
-- Reset the database recovery model.
ALTER DATABASE STUDENT
SET RECOVERY FULL;

GO

sp_spaceused ( In MSSQL Server )

sp_spaceused command used in MSSQL 2005 or above version. This command return a current database disk space (hard drive) used.
Let’s see in details.

This command give details of disk space reserved, and disk space used by a table, indexed view, or Service Broker queue in the current database, or displays the disk space reserved and used by the whole database.

Example

USE [Master]
GO
EXEC sp_spaceused

GO

Results










Now, let us understand the above result sets, lets check by the column names
·         database_size: Database size (data files + log files) = 5 MB
·         unallocated space: Space that is not reserved for use either by data or log files (Space Available) = 1.26 MB
·         reserved: Space that is reserved for use by data and log files = 2.74 MB
·         data: Space used by data = 1176 KB/1024 = 1.14 MB
·         index_size: Space used by indexes = 1184  KB/1024 = 1.15 MB
·         unused: Portion of the reserved space, which is not yet used = 448 KB/1024 = 0.43 MB


Need Permission to execute this command:
sp_spaceused is granted to the public role.

Camera Task In Phone 8



Use the camera capture task to enable users to take a photo from your application using the built-in Camera application. If the user completes the task, an event is raised and the event handler receives a photo in the result. On Windows Phone 8, if the user accepts a photo taken with the camera capture task, the photo is automatically saved to the phone's camera roll. On previous versions of Windows Phone, the photo is not automatically saved.

Source Code

HOW TO BACKUP ALL DATABASES IN SQL SERVER




This is a SQL script of get all Databases Backup in particular folder.
backup file name will be "DataBaseName_{Month}_{Date}_{Year}.bak"

Notes :

1) Current user have full access of backup database.
2) Remote drive setup is extra step you have to perform in sql server in order to backup your dbs to remote drive. 
3) you have to chnage you sql server accont to a network account and add that user to have full access to the network drive you are backing up to.

Kendo UI Grid in Asp.Net MVC4





Today I demonstrate the example of Kendo UI
Kendo UI is very nice, rich and professional user interface.
I will demonstrate you that how can we use the Kendo UI with ASP.NET MVC4

WebGrid in ASP.NET MVC4




Webgrid is very nice feature in mvc 4.
I try my best to represent entire demonstration in very easy manner and step by step implementing WebGrid.


Image Store and Retrieve From SQL Server

Store Image in Database

private void button1_Click(object sender, EventArgs e)
        {
            System.Data.SqlClient.SqlConnection cnn = new System.Data.SqlClient.SqlConnection();
            cnn.ConnectionString=@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True";
                cnn.Open();
            System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
            cmd.Connection = cnn;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("Id",Convert.ToDecimal(textBox1.Text));

            byte[] img;
            Cls_Img clsimg=new Cls_Img();

            // convert image to byte array using class method
            img=clsimg.Img2Byte(pictureBox1.Image);

            cmd.Parameters.AddWithValue("Img",img);
            cmd.CommandText = "Insert_Table1";
            cmd.ExecuteNonQuery();
            MessageBox.Show("Inset Completed");
        }


class Cls_Img
    {

        public byte[] Img2Byte(System.Drawing.Image imagein)
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            try
            {
                //Here We Use MemoryStream Class To Write/Read Our Data
                //Because MemoryStream Class is Write Data On Memory(RAM)
  //So we Doesn't Need To Save a File Which Contain Binary Data on HardDrive.

                imagein.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);

            }
            catch (Exception)
            {
            }
            //ms.ToArray Return Byte Array
            return ms.ToArray();
        }


Retrieve Image From Database
 

private void button3_Click(object sender, EventArgs e)
        {
            System.Data.SqlClient.SqlConnection cnn = new System.Data.SqlClient.SqlConnection();
            System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
            System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter();
            System.Data.DataSet ds = new DataSet();
            System.Data.DataTable dt = new DataTable();


            cnn.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True";
            cnn.Open();
           
            cmd.Connection = cnn;
            cmd.CommandText = "Select * from Table1 where id=" + Convert.ToDecimal(textBox1.Text);
           
            da.SelectCommand = cmd;
           
            da.Fill(ds, "a");
           
            dt = ds.Tables["a"];

            Cls_Img clsimg = new Cls_Img();

            byte[] x;
            // get byte array from database
            x = (byte[])dt.Rows[0][1];

            // converting byte array to image using class method
            pictureBox2.Image = clsimg.byteArrayToImage(x);
        }



        public System.Drawing.Image byteArrayToImage(byte[] byteArrayIn)
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream(byteArrayIn);
            //Here We Use MemoryStream Class To Write Image
            // Input a BteArray is Directly Convert in Image
            // Using System.Drawing.Image.FromStream
            // System.Drawing.Image.FromStream Input Perameter is ByteArray
            // System.Drawing.Image.FromStream Output  is System.Drawing.Image

            System.Drawing.Image returnImage = System.Drawing.Image.FromStream(ms);

            // Return Image
            return returnImage;
        }
}
    

 

Insert, Update, Delete using stored procedure in C#

Stored Procedure

CREATE PROCEDURE dbo.Insert_Table1  /* Procedure Name  dbo.Insert_Table1 */
(
@id numeric(18,0), /* Input Parameter */
@name varchar(50)  /* Input Parameter */
)
AS
insert into Table1
values (
@id ,
@name
)
return

Access Stored Procedure Using C# 

private void btnInsert_Click(object sender, EventArgs e)
        {
            SqlConnection cnn = new SqlConnection();  
            cnn.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True";
              cnn.Open();
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
            cmd.Connection = cnn;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("id",Convert.ToInt32(textBox1.Text));
            cmd.Parameters.AddWithValue("name", textBox2.Text);
            cmd.CommandText = "Insert_Table1";
            cmd.ExecuteNonQuery();
            MessageBox.Show("Data inserted Successfully");
        }


  • Stored procedure 80% faster compare to SQL QUERY.
  • Stored procedure reducing work load.
  • Stored procedure stored in database as object.
  • Stored procedure also return a value. 
  Download Source Coe