Search This Blog

Friday, December 23, 2011

Shrink Database log files in SQL Server 2008

If you want to shrink the databases log file then here is the process for SQL Server 2008.

-Right click on the Database --> Tasks --> Shrink --> Files

-Select the 'File Type' as 'Log'

-Select 'Reorganize pages before releasing unused space' and modify the size.

-Click 'OK'

Wednesday, November 9, 2011

SQL Server - Simple Cursor Example

A very simple cursor to add the integers from a table variable. The following query declares a table
variable with single column, inserts 3 integers into the table. Next, the cursor is declared and it
adds up the integers and prints the total.
 
--Query Begins--
--Declare table to store integers with single column
DECLARE @NumTable TABLE (Number int NULL)

--Inserts 3 integers into the table
INSERT INTO @NumTable (Number) VALUES (10)
INSERT INTO @NumTable (Number) VALUES (20)
INSERT INTO @NumTable (Number) VALUES (30)

--Declare the variables
DECLARE @Num INT
DECLARE @Total INT = 0

--Declare the cursor
DECLARE Cur CURSOR FOR
SELECT Number FROM @NumTable

--Open the cursor
OPEN Cur
FETCH NEXT FROM Cur INTO @Num

WHILE @@FETCH_STATUS = 0

BEGIN

--Add the integers
SELECT @Total = @Total + @Num

FETCH NEXT FROM Cur INTO @Num

--Close the cursor
END
CLOSE Cur
DEALLOCATE Cur

--Select the total
SELECT @Total
--Query Ends--

Tuesday, November 8, 2011

SQL Error : String or Binary data would be truncated




String or Binary data would be truncated

This is well known error. This could occur when your are trying to insert some values into
a table through stored procedure or query etc.

Solution: This error occurs when one of the column SIZE in the table is very small compared
to the value being inserted. So closely check all the column sizes, change it accordingly
and then try to insert the values.

Monday, November 7, 2011

SQL Server- Syntax to create simple table

Note the syntax to create a very simple table with two colums for sql server! We can do much more while creating tables like applying constraints, allow NULLs or NOT NULLS etc.

USE <DataBaseName>


GO

CREATE TABLE <TableName>

(

ProductID  VARCHAR(25),

ProductName VARCHAR(25)

)

GO

Tuesday, September 14, 2010

Transports in Windows Communication Foundation

Transports in Windows Communication Foundation
The main transports used in Windows Communication Foundation (WCF) are HTTP, HTTPS, TCP, and named pipes. The topics in this section discuss choosing among these transports, configuring the transport, and setting tuning properties.
Choosing a Transport
This topic discusses criteria for choosing among the three main transports that are included in Windows Communication Foundation (WCF): HTTP, TCP, and named pipes.
The WCF programming model separates endpoint operations (as expressed in a service contract) from the transport mechanism that connects two endpoints. This gives you the flexibility to decide how to expose your services to the network. If you must connect to an existing client or server, you may not have a choice about using a particular transport. However, WCF services can be made accessible through multiple endpoints, each with a different transport. When a single transport does not cover the intended audience for your service, consider exposing the service over multiple endpoints. Client applications can then use the endpoint that is best for them.
When to Use HTTP Transport
HTTP is a request/response protocol between clients and servers. The most common application consists of Web-browser clients that communicate with a Web server. The client sends a request to a server, which listens for client request messages. When the server receives a request, it returns a response, which contains the status of the request. If successful, optional data, such as a Web page, an error message, or other information is returned.The HTTP protocol is not connection-based—once the response is sent, no state is maintained. To handle multiple-page transactions, the application must persist any necessary state.
When to Use the TCP Transport
TCP is a connection-based, stream-oriented delivery service with end-to-end error detection and correction. Connection-based means that a communication session between hosts is established before exchanging data. A host is any device on a TCP/IP network identified by a logical IP address.TCP provides reliable data delivery and ease of use. Specifically, TCP notifies the sender of packet delivery, guarantees that packets are delivered in the same order in which they are sent, retransmits lost packets, and ensures that data packets are not duplicated. Note that this reliable delivery applies between two TCP/IP nodes, and is not the same thing as WS-ReliableMessaging, which applies between endpoints, no matter how many intermediate nodes they may include.
When to Use the Named Pipe Transport
A named pipe is an object in the Windows operating system kernel, such as a section of shared memory that processes can use for communication. A named pipe has a name, and can be used for one-way or duplex communication between processes on a single machine.When communication is required between different WCF applications on a single computer, and you want to prevent any communication from another machine, then use the named pipes transport. An additional restriction is that processes running from Windows Remote Desktop may be restricted to the same Windows Remote Desktop session unless they have elevated privileges.

Tuesday, September 7, 2010

WCF Services

WCF Services


All communication with a Windows Communication Foundation (WCF) service occurs through the endpoints of the service. Endpoints provide clients access to the functionality offered by a WCF service.

Each endpoint consists of four properties:

An address that indicates where the endpoint can be found. The address uniquely identifies the endpoint and tells potential consumers of the service where it is located. It is represented in the WCF object model by the EndpointAddress class.

A binding that specifies how a client can communicate with the endpoint. The binding specifies how to communicate with the endpoint. This includes:

-The transport protocol to use (for example, TCP or HTTP).

-The encoding to use for the messages (for example, text or binary).

-The necessary security requirements (for example, SSL or SOAP message security).

A contract that identifies the operations available. The contract outlines what functionality the endpoint exposes to the client. A contract specifies:

-What operations can be called by a client.

-The form of the message.

-The type of input parameters or data required to call the operation.

-What type of processing or response message the client can expect.

A set of behaviors that specify local implementation details of the endpoint. You can use endpoint behaviors to customize the local behavior of the service endpoint. Endpoint behaviors achieve this by participating in the process of building a WCF runtime. An example of an endpoint behavior is the ListenUri property, which allows you to specify a different listening address than the SOAP or Web Services Description Language (WSDL) address.

Data transfer and serialization in WCF service.

The Windows Communication Foundation (WCF) can be thought of as a messaging infrastructure. Service operations can receive messages, process them, and send them messages. Messages are described using operation contracts. For example, consider the following contract.

[ServiceContract] - This shows what services are offered to the client.

[OperationContract] - This shows what operations are exposed within the service to the client.

[DataContract] - This is used when the parameter passed need to act as both for request and reply messages. They makes use of DataContractSerializer.

[MessageContract] - This is used to represent the request and the reply message using single type. This can be implemented using datacontract also. But message contract avoids unnecessary levels of wrapping in the resultant xml. Also, message contracts can specify what shld be the message body and what shld be message header.

Sessions, Instancing, and Concurrency in Windows Communication Foundation

A session is a correlation of all messages sent between two endpoints. Instancing refers to controlling the lifetime of user-defined service objects and their related InstanceContext objects. Concurrency is the term given to the control of the number of threads executing in an InstanceContext at the same time.

Monday, September 6, 2010

LINQ

LINQ


Language-Integrated Query (LINQ) is a new feature in Visual Studio 2008 and the .NET Framework 3.5. LINQ extends powerful query capabilities to the language syntax of C# and Visual Basic in the form of standard, easily-learned query patterns. This technology can be extended to support potentially any kind of data store. The .NET Framework 3.5 includes LINQ provider assemblies that enable the use of LINQ for querying .NET Framework collections, SQL Server databases, ADO.NET Datasets, and XML documents.

The components of LINQ that are part of the .NET Framework 3.5 are:

The System.Linq namespace, which contains the set of standard query operators and types and interfaces that are used in the infrastructure of a LINQ query. This namespace is in the System.Core.dll assembly.

The System.Data.Linq namespace, which contains classes that support interaction with relational databases in LINQ to SQL applications.

The System.Data.Linq.Mapping namespace, which contains classes that can be used to generate a LINQ to SQL object model that represents the structure and content of a relational database.

The System.Xml.Linq namespace, which contains the classes for LINQ to XML. LINQ to XML is an in-memory XML programming interface that enables you to modify XML documents efficiently and easily. Using LINQ to XML, you can load XML, serialize XML, create XML trees from scratch, manipulate in-memory XML trees, and validate by using XSD. You can also use a combination of these features to transform XML trees from one shape into another.

New types in the System.Web.UI.WebControls and System.Web.UI.Design.WebControls namespaces. These new types, such as LinqDataSource, support the use of LINQ in ASP.NET Web pages through a data source control.

The DataRowComparer, DataRowExtensions, and DataTableExtensions classes in the System.Data namespace support LINQ queries against ADO.NET DataSet objects.

In the class library, the LINQ extension methods that apply to a class are listed in the members page for the class, in the Contents pane, and in the Index pane.