Sunday, December 1, 2013

How to create, alter and Drop a Constraints in SQL SERVER

To alter a constraints we need to drop that constraints first.
then recreate that constraints.

Follow this syntax, to Drop Constraints.

ALTER TABLE [dbo].[TableName]  DROP CONSTRAINT [FK_Config_ConstraintsName]

How to check a constraint is exist or not ?


REFERENTIAL constraints are saved in REFERENTIAL_CONSTRAINTS table.

SELECT
    *
    FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS

    WHERE CONSTRAINT_NAME   ='FK_EVENT_CONFIGURATION_SCREEN_MASTER'

Tuesday, November 12, 2013

How To Encript and Decript Web.Config CONNECTION STRING

Step to Encript Connection string :

Step 1: Open CMD As Administrator

step 2:  cd C:\Windows\Microsoft.NET\Framework\v4.0.30319

step 3: aspnet_regiis -pc "MyKeys" -exp

 Step 4:
**** For Local Machine ******
C:\Windows\Microsoft.NET\Framework\v4.0.30319>aspnet_regiis -pa "MyKeys" "Max70-PC\Max72"

**** For Server Machine ******
C:\Windows\Microsoft.NET\Framework\v4.0.30319>aspnet_regiis -pa "MyKeys" "NT AUTHORITY\NETWORK SERVICE"

Step 5 : Add This section to your Web.Config File in "configuration" Section

  <configProtectedData>
    <providers>
      <add name="MyProvider"  type="System.Configuration.RsaProtectedConfigurationProvider,System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
           description="Uses RsaCryptoServiceProvider to encrypt and decrypt"
           keyContainerName="MyKeys"
           useMachineContainer="true"
           />
    </providers>

  </configProtectedData>



**** -each site must have a identity in IIS. take that ID. i.e -Site "4" . ***

Step 6:  C:\Windows\Microsoft.NET\Framework\v4.0.30319>aspnet_regiis -pe "connectionStrings" -site "4"  -app "/" -prov "RsaProtectedConfigurationProvider"



Step to decript Connection string :
Step 1: Open CMD As Administrator

Step 2:  cd C:\Windows\Microsoft.NET\Framework\v4.0.30319

Step 3:   aspnet_regiis -pd "connectionStrings" -site "4"  -app "/"

Ref : http://msdn.microsoft.com/en-us/library/2w117ede.aspx

Tuesday, October 22, 2013

Delete all the foreign key relation in your SQL Server database


DECLARE @cmd nvarchar(1000)
DECLARE @fk_table_name nvarchar(1000)
DECLARE @fk_name nvarchar(1000)

DECLARE cursor_fkeys CURSOR FOR
   SELECT  OBJECT_NAME(fk.parent_object_id) AS fk_table_name,
                  fk.name as fk_name
   FROM    sys.foreign_keys fk  JOIN 
           sys.tables tbl ON tbl.OBJECT_ID = fk.referenced_object_id
   -- WHERE OBJECT_NAME(fk.parent_object_id) in ('table1', 'table2', 'table2')

OPEN cursor_fkeys
FETCH NEXT FROM cursor_fkeys
      INTO @fk_table_name, @fk_name

WHILE @@FETCH_STATUS=0
BEGIN
      -- build alter table statement
      SET @cmd = 'ALTER TABLE [' + @fk_table_name + '] DROP CONSTRAINT [' + @fk_name + ']'
      -- execute it
      exec dbo.sp_executesql @cmd

      FETCH NEXT FROM cursor_fkeys
      INTO @fk_table_name, @fk_name
END
CLOSE cursor_fkeys

DEALLOCATE cursor_fkeys

Saturday, August 24, 2013

How to copy directory using VB.Net



Forder to folder copy :


Dim newWfFilePath As String = Web.HttpContext.Current.Server.MapPath(filepath)
Dim defaultPath As String = Web.HttpContext.Current.Server.MapPath(copyfrom)
Dim directorys() As String = Directory.GetDirectories(defaultPath)
               
For Each folder As String In directorys
          Dim folderName() As String = folder.Split("\"c)
          Dim directoryName As String = folderName(folderName.Length - 1)
 If (Directory.Exists(newWfFilePath + "/" + directoryName)) Then
 Else
     Directory.CreateDirectory(newWfFilePath + "/" + directoryName)
     Dim strFiles() As String = Directory.GetFiles(defaultPath + "/" + directoryName)


     For Each strFile As String In strFiles
          Dim FileName() As String = strFile.Split("\"c)
          System.IO.File.Copy(strFile, newWfFilePath + "/" + directoryName +  
                              "/"+FileName(FileName.Length - 1))

     Next

 End If
Next

Wednesday, July 3, 2013

Add JavaScript map to Html Header using VB.Net




In Page Load event

Dim scripttag = New HtmlGenericControl("script")


                scripttag.Attributes.Add("type", "text/javascript")


                scripttag.InnerHtml = "var controls="[{‘key1’:’value1’, ‘key2’:’value2’},    {="[{‘key1’:’value3’, ‘key2’:’value4’}]"


                Page.Header.Controls.Add(scripttag)

Sunday, June 30, 2013

Jquery Date Picker in dd/mm/yyyy Format.

$(document).ready(function () {
        $('.datepicker').datepicker({
            numberOfMonths: 2,
            dateFormat: 'dd/mm/yy',
            changeMonth: true,
            changeYear: true,
            autoSize: true,
            minDate: new Date(),
            maxDate: '+363d',
            showAnim: 'fadeIn',
            yearRange: '2013:2020',
            showOn: 'focus',
            buttonImage: '/Content/images/calendar.gif',
            buttonImageOnly: 'false'
        });
    })

Sunday, February 24, 2013

Select all Html Element whose ID start with 'txt_'



<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<script>
    $(document).ready(function () {
        $("button").click(function () {
            $("a[target='_blank']").hide();
            $('[id^="txt_"]').hide();
        });
    });
</script>
</head>
<body>

<h2>This is a heading</h2>
<p id="txt_p">This is a paragraph.</p>
<p id="txt_p1">This is another paragraph.</p>

<button>Click me</button>

</body>
</html>

Thursday, January 10, 2013

Kendo - KnockOut Grid Bind




<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />

<link href="@Url.Content("~/Content/kendo.common.min.css")" rel="stylesheet" type="text/css" />

<link href="@Url.Content("~/Content/kendo.blueopal.min.css")" rel="stylesheet" type="text/css" />



<script src="@Url.Content("~/Scripts/jquery-1.8.3.js")" type="text/javascript"></script>

<script src="../../Scripts/knockout-2.2.0.debug.js" type="text/javascript"></script>

<script src="../../Scripts/kendo.all.min.js" type="text/javascript"></script>

<script src="../../Scripts/knockout-kendo.min.js" type="text/javascript"></script>


HTML

                                              


<div data-bind='kendoGrid:gridConfig'></div>  

                                               

JavaScript


<script language="javascript" type="text/javascript">

$(document).ready(function () {
      
        $.ajaxSetup({ async: false });

        //var Data= [{ "ShipCity": "Kolkata", "ShipName": "Pinaki GROUP" }, { "ShipCity": "Mumbai", "ShipName": "Pinaki SOL"}];
        var Data = null;

        function DataFunction() {
            $.post("/BkCode/BookResult", null, function (d) {

                Data = d;
            });
            return Data;

        }
      

        var ViewModel = function () {
            this.gridConfig = {
                data: null,
                dataSource: {
                    type: "odata",
                    data: DataFunction(), //This is use to access data from database using jQuery
                                          //   and return data in Json format
                    //data: Data,
                    schema: {
                        model: {
                            fields: {
                                ShipCity: {
                                    type: "string"
                                   
                                },

                                ShipName: {
                                    type: "string"


                                }
                            }
                        }
                    },
                    pageSize: 10 //,
                    //serverPaging: true,
                    //serverFiltering: true,
                    //serverSorting: true
                },
                columns: [{
                    field: "ShipCity",
                    title: "Id",
                    filterable: false
                },
                {
                    field: "ShipName",
                    title: "Company Name",
                    filterable: true
                },
                {
                    command: ["edit", "destroy"],
                    filterable: false
                }] ,

                height: 550,
                scrollable: false,
                pageable: true,
                sortable: true,
                groupable: true,
                filterable: true,
                editable: "inline", //popup
                save: function () {
                    this.refresh();
                }
            };
        };
        ko.applyBindings(new ViewModel());
    })

</script>

C#

public JsonResult BookResult()
        {
            var result = from s in bk.GetPrmCompanies()
                         select new book{
                             ShipCity = s.Id,
                             ShipName = s.CoNames
                         };
            DB.Configuration.ProxyCreationEnabled = false;

            return Json(result, JsonRequestBehavior.AllowGet); //Content(sd, "text/xml");

        }
 




SQL Optimization

  SQL Optimization  1. Add where on your query  2. If you remove some data after the data return then remove the remove condition in the sel...