Monday 20 July 2015

......BCP (BULK Export & Import)......

BCP COPY To BCP IMPORT, BULK INSERT in SQL Server



Note : -  BCP Queries can not run in wrapping text,  run in one line statement.

--START-----Exporting  format file using fmt extension-------FORMAT file in text format----

EXEC xp_cmdshell 'bcp DataBaseName..TableName format nul -n -f C:\Path_n.fmt -S ServerName\ServerName_2008 -T' 

---END----Exporting  format file using fmt extension-------FORMAT file in text format--------

--START-----Exporting  format file using fmt extension-------FORMAT file in XML format
--

EXEC xp_cmdshell 'bcp DataBaseName..TableName format nul -c -t~ -f D:\BCP_FormatFiles_CSVData\FileName.xml -S ServerName\ServerName_2008_2008 -x -T'
 
---END----Exporting  format file using fmt extension-------FORMAT file in XML format


---START-------Exporting data with format in csv file -----OUT Command----------------

EXEC xp_cmdshell 'bcp TableName..Databasename out D:\BCP_FormatFiles_CSVData\_Records.csv -f D:\BCP_FormatFiles_CSVData\QDeals.xml -S ServerName\ServerName_2008 -T -L 100 -r'

 ---END-------Exporting data with format in csv file -----OUT Command------------------


---START--------Importing data with format in csv file ----IN
Command ----------------------

EXEC xp_cmdshell 'bcp Master..BCPTableNoteDeals in D:\FileName_06Jul2015_112447.csv -f C:\PersonFormat_c.xml -S ServerName\ServerName –T'

---END--------Importing data with format in csv file ----IN
Command --------------------


Note:- Bulk insert command can allow for wrapping query text  but BCP not Allowed  
---START-----BULK INSERT Using CSV--XML------Files ----------------------------

BULK INSERT Master..BCPTableNoteDeals
FROM 'D:\BCP_FormatFiles_CSVData\QDeals_Records.csv' WITH (FORMATFILE='D:\BCP_FormatFiles_CSVData\QDeals.xml');
GO

---END-----BULK INSERT Using CSV--XML------Files -------------------------------

---START-----Query_OUT Command in Where Clause-----------------------------------
SET @DatabaseName ='DatabaseNametablename'   
SET @minpo = N'Where clauser'
SELECT @sql = 'bcp "SELECT * FROM DatabaseNm.dbo.TablNm where Note_Product_Name= ''' + @minpo + '''  " queryout d:\test.txt -c -t, -T -S ' + @@servername
EXEC master..xp_cmdshell @sql
---------------------------------------------------------------------------------------------

DECLARE @sql111 VARCHAR(8000)
SELECT @sql111 = 'bcp " SELECT * FROM DB.dbo.TBN " queryout d:\NewNoteMastertxtImport.csv -c -t~ -T -S ' + @@servername
EXEC master..xp_cmdshell @sql111
----------------------------------------------------------------------------------------------
---END-----Query_OUT Command  in Where Clause-------------------------------------


------------------Get Table Size Details ----------------------

 EXEC sp_msforeachtable 'sp_spaceused ''?''' 
 
-------------------Get Server Info

SELECT  @@servername name ,  substring(@@version  , 1 ,26) version 








Thursday 14 March 2013

Gives Browser Security


   Gives Browser Security

<!DOCTYPE html>
<html>
<head>
<script>
function displayDate()
{
document.getElementById("demo").innerHTML=Date();

var newwin = window.open("http://www.gmail.com", "mywin", "left=0,top=0,width=" + screen.width - 15 + ",height=" + screen.height - 30 + ",toolbar=0,resizable=1,scrollbars=1,status=1,directories=0");

 window.opener = top;
 window.close();
 newwin.focus();
}
</script>
<script type="text/javascript">
      
        window.history.forward(1);
      

        document.onkeydown = function() {
            //alert(window.event.keyCode);
            if ((window.event.keyCode == 13) || (window.event.keyCode == 116) || (window.event.keyCode == 122) || ((window.event.keyCode == 78) && (window.event.ctrlKey)) || ((window.event.keyCode == 82) && (window.event.ctrlKey)) || ((window.event.keyCode == 67) && (window.event.ctrlKey)) || ((window.event.keyCode == 86) && (window.event.ctrlKey)) || ((window.event.keyCode == 88) && (window.event.ctrlKey)) || ((window.event.keyCode == 222) && (window.event.ctrlKey))) {
                window.event.returnValue = false;
                window.event.cancelBubble = true;
                window.event.keyCode = 0;
                return false;
            }
        }

     
    </script>

  <script type="text/javascript">

        document.oncontextmenu = cancelit;

        function cancelit() {
            event.returnValue = false;
        }

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

        function cancelBack() {
            if ((event.keyCode == 8 ||
           (event.keyCode == 37 && event.altKey) ||
           (event.keyCode == 39 && event.altKey))
            &&
           (event.srcElement.form == null || event.srcElement.isTextEdit == false)
          ) {
                event.cancelBubble = true;
                event.returnValue = false;
                return false;
            }
        }  
 
</script>

</head>
<body>

<h1>Hide Url for IE Browser</h1>

<p id="demo">This is a paragraph.</p>

<button type="button" onclick="displayDate()">Display Date</button>


</body>

</html>

Thursday 20 December 2012

  <script type="text/javascript" language="javascript">
    function checkValidateData()
    {
    var che =document.getElementById("txtChe.Text");
    var phy=document.getElementById("txtPhy.Text");
    var math=document.getElementById("txtMath.Text");
 
//    if(isNaN(che))
//    {
//    alert('Please Enter Marks');
//    return true;
//    }
    
    var uid;
    var temp=document.getElementById("<%=txtChe.ClientID %>");
    uid=temp.value;
    if(uid=="")
    {
    alert ('Please Enter UserName');
    return false;
    }

    if(isNaN(uid))
    {
    alert('Please Enter number');
    uid.Focus();
    return false;
    }
   
    }
    </script>



  Grade

protected void Button1_Click(object sender, EventArgs e)
        {
            if (int.Parse(txtphy.Text) < 35 || int.Parse(txtphy.Text) < 35 || int.Parse(txtChe.Text) < 35)
            {
                Response.Write("Fail");
            }
            else
            {
                txtTot.Text = Convert.ToString((int.Parse(txtphy.Text) + int.Parse(txtMaths.Text) + int.Parse(txtChe.Text)));
                txtper.Text = Convert.ToString(int.Parse(txtTot.Text) / 3);

                if (int.Parse(txtper.Text) == 35 && int.Parse(txtper.Text) >= 49)
                {
                    Response.Write("Your Grad Id C");
                }
                else
                    if (int.Parse(txtper.Text) > 49 && int.Parse(txtper.Text) <= 59) { Response.Write("Your Grad Id B"); }
                    else
                        if (int.Parse(txtper.Text) >= 60 && int.Parse(txtper.Text) <= 65) { Response.Write("Your Grad Id A"); }
                        else
                            if (int.Parse(txtper.Text) > 65 && int.Parse(txtper.Text) <= 75) { Response.Write("Your Grad Id A+"); }


             }
        }


 ---------------------------------------------





  <script type="text/javascript" language="javascript">
    function checkValidateData()
    {
    var che =document.getElementById("txtChe.Text");
    var phy=document.getElementById("txtPhy.Text");
    var math=document.getElementById("txtMath.Text");
 
//    if(isNaN(che))
//    {
//    alert('Please Enter Marks');
//    return true;
//    }
    
var uid;
var temp=document.getElementById("<%=txtChe.ClientID %>");
uid=temp.value;
if(uid=="")
{
alert ('Please Enter UserName');
return false;
}
   
   
    }
    </script>
 

Tuesday 18 December 2012

Cross Page Posting

Cross Page Posting



Response.Write(
((TextBox)this.PreviousPage.FindControl("MyTextBox")).Text)

In order to provide the strongly typed access to previous page, you can specify the previous page in PreviousPageType directive; since you have strongly typed reference of previous page you can now easily access its public members without any typecasting. Lets see how (here login page postbacks to UserAuthenticate page).

Login.aspx
<asp:Textbox ID="TextBoxUserName" Runat="server" />
<asp:Textbox ID="TextBoxPassword" Runat="server" />
<asp:Button ID="ButtonLogin" Runat="server" Text="Login"
         PostBackUrl="UserAuthenticate.aspx" />

Expose the following properties in code behind file
public TextBox UserName
{
    get
    {
        return TextBoxUserName;
    }
}

public TextBox Password
{
    get
    {
        return TextBoxPassword;
    }
}

UserAuthenticate.aspx
<%@ PreviousPageType VirtualPath="~/Login.aspx" %>
<script runat="server">   
protected void Page_Load(object sender, System.EventArgs e)
{
    String username = PreviousPage.UserName.Text;
    String password = PreviousPage.Password.Text;
    // Authenticate username/password
}

Monday 17 December 2012

WCF and Const,Readonly,Static


 WCF Windows Communication Foundation



Q1. What is WCF?
WCF stands for Windows Communication Foundation. It is a Software development kit for developing services on Windows. WCF is introduced in .NET 3.0. in the System.ServiceModel namespace. WCF is based on basic concepts of Service oriented architecture (SOA)

Q2. What is endpoint in WCF service?
The endpoint is an Interface which defines how a client will communicate with the service. It consists of three main points: Address,Binding and Contract.

Q3. Explain Address,Binding and contract for a WCF Service?
Address:Address defines where the service resides.
Binding:Binding defines how to communicate with the service.
Contract:Contract defines what is done by the service.

Q4. What are the various address format in WCF?
a)HTTP Address Format:--> http://localhost:
b)TCP Address Format:--> net.tcp://localhost:
c)MSMQ Address Format:--> net.msmq://localhost:

Q5. What are the types of binding available in WCF?
A binding is identified by the transport it supports and the encoding it uses. Transport may be HTTP,TCP etc and encoding may be text,binary etc. The popular types of binding may be as below:
a)BasicHttpBinding
b)NetTcpBinding
c)WSHttpBinding
d)NetMsmqBinding

Q6. What are the types of contract available in WCF?

The main contracts are:
a)Service Contract:Describes what operations the client can perform.
b)Operation Contract : defines the method inside Interface of Service.
c)Data Contract:Defines what data types are passed
d)Message Contract:Defines wheather a service can interact directly with messages

Q7. What are the various ways of hosting a WCF Service?
a)IIS b)Self Hosting c)WAS (Windows Activation Service)

Q8. WWhat is the proxy for WCF Service?

A proxy is a class by which a service client can Interact with the service.
By the use of proxy in the client application we are able to call the different methods exposed by the service


Q9. How can we create Proxy for the WCF Service?

We can create proxy using the tool svcutil.exe after creating the service.
We can use the following command at command line.
svcutil.exe *.wsdl *.xsd /language:C# /out:SampleProxy.cs /config:app.config

Q10.What is the difference between WCF Service and Web Service?
a)WCF Service supports both http and tcp protocol while webservice supports only http protocol.
b)WCF Service is more flexible than web service.

Q11.What is DataContract and ServiceContract?Explain
Data represented by creating DataContract which expose the
data which will be transefered /consumend from the serive
to its clients.

**Operations which is the functions provided by this
service.

To write an operation on WCF,you have to write it as an
interface,This interface contains the "Signature" of the
methods tagged by ServiceContract attribute,and all methods
signature will be impelemtned on this interface tagged with
OperationContract attribute.

and to implement these serivce contract you have to create
a class which implement the interface and the actual
implementation will be on that class





const and readonly perform a similar function on data members, but they have a few important differences.

const

A constant member is defined at compile time and cannot be changed at runtime. Constants are declared as a field, using the const keyword and must be initialized as they are declared. For example;
public class MyClass
{
  public const double PI = 3.14159;
}
PI cannot be changed in the application anywhere else in the code as this will cause a compiler error.
Constants must be a value type (sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, or bool), an enumeration, a string literal, or a reference to null.
Since classes or structures are initialized at run time with the new keyword, and not at compile time, you can't set a constant to a class or structure.
Constants can be marked as public, private, protected, internal, or protected internal.
Constants are accessed as if they were static fields, although they cannot use the static keyword.
To use a constant outside of the class that it is declared in, you must fully qualify it using the class name.

readonly

A read only member is like a constant in that it represents an unchanging value. The difference is that a readonly member can be initialized at runtime, in a constructor as well being able to be initialized as they are declared. For example:
public class MyClass
{
  public readonly double PI = 3.14159;
}




public class MyClass
{
  public readonly double PI;
 
  public MyClass()
  {
    PI = 3.14159;
  }
}
Because a readonly field can be initialized either at the declaration or in a constructor, readonly fields can have different values depending on the constructor used. A readonly field can also be used for runtime constants as in the following example:
public static readonly uint l1 = (uint)DateTime.Now.Ticks;
Notes
  • readonly members are not implicitly static, and therefore the static keyword can be applied to a readonly field explicitly if required.
  • A readonly member can hold a complex object by using the new keyword at initialization.


[edit]

static

Use of the static modifier to declare a static member, means that the member is no longer tied to a specific object. This means that the member can be accessed without creating an instance of the class. Only one copy of static fields and events exists, and static methods and properties can only access static fields and static events. For example:
public class Car
{
  public static int NumberOfWheels = 4;
}
The static modifier can be used with classes, fields, methods, properties, operators, events and constructors, but cannot be used with indexers, destructors, or types other than classes.
static members are initialized before the static member is accessed for the first time, and before the static constructor, if any is called. To access a static class member, use the name of the class instead of a variable name to specify the location of the member. For example:
int i = Car.NumberOfWheels;