Tuesday, 30 April 2013

Insert multiple rows in one statement in SQL Server 2008

Row Constructor is new feature to SQL Server 2008 that allows insertion of multiple rows of data at once. Say we create a table row_constructor
create table row_construct
(ID int identity(1,1) not null primary key
, type varchar(20) not null default 'N/A'
, name varchar(100) not null default 'N/A'

insert row_construct (type,name) values ('A', 'Garments')
insert row_construct (type,name) values ('B', 'Sports Equipments')
insert row_construct (type,name) values ('C', 'Cosmetics')
insert row_construct (type,name) values ('A', 'Swim Wears')
insert row_construct (type,name) values ('A', 'Sports Garments')

--but with the help of row constructors we can insert the same data using single insert statement as below

insert row_construct (type,name) values
('A', 'Garments'),('B', 'Sports Equipments'),('C', 'Cosmetics'),('A', 'Swim Wears'),('A', 'Sports Garments');
--we can also write the same as
insert row_construct
select type, name from (values
('A', 'Garments'),
('B', 'Sports Equipments'),
('C', 'Cosmetics'),
('A', 'Swim Wears'),
('A', 'Sports Garments'))
 as rowtables (type, name);


insert row_construct

('A', 'Garments'),
('B', 'Sports Equipments'),
('C', 'Cosmetics'),
('A', 'Swim Wears'),
('A', 'Sports Garments')

See the Results...
More  Info:  http://blog.sqlauthority.com/2008/04/16/sql-server-2008-row-constructors-load-temp-tables-from-stored-procedures/ 

Monday, 22 April 2013

System.Net.WebException: The operation has timed-out in WebService

Actual Error :
{System.Net.WebException: The operation has timed out
   at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request)
   at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request)
   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)

Inner Exception :
  Everytime inner exception will not be same.So you have check it while debugging.


If it possible to modify timeout session timing in web_service increase it.
From CS Code:
 Service1 ws = new Service1();
 ws.Timeout = 300000;

Check the solution.
Enjoy :) :) :)