Friday, March 23, 2012

sql Server For Loop

--Declare a Flag
DECLARE @Flag INT
--Assign Value to Flag
SET @Flag = 403
--Start LOOP
WHILE (@Flag < 408)
BEGIN
BEGIN
DELETE Connection WHERE ID=@Flag
PRINT @Flag
--Increment the flag Value
SET @Flag = @Flag + 1
END
--Condition for stopping the LOOP
IF(@Flag > 407)
BREAK
--Continue if Condition is Satisfied
ELSE
CONTINUE
END

OUTPUT:
(0 row(s) affected)
403

(0 row(s) affected)
404

(0 row(s) affected)
405

(0 row(s) affected)
406

(0 row(s) affected)
407

Switch and Case in C# and SQL Formats


IN C# We can Write As
 fallows:

int connectionFormat=0;
string strConnectionType="WebSite";

switch (strConnectionType)
{
case "Phone":
connectionFormat = 0;
break;
case "Email":
connectionFormat = 1;
break;
case "WebSite":
connectionFormat = 2;
break;
case "Others":
connectionFormat = 3;
break;
default:
connectionFormat = 0;
break;
}

------
OutPut :
connectionFormat=2
 
-----------

SQL Server Statement
------------------

SELECT
CASE
WHEN C.Connectionformat = 0 THEN 'Phone'
WHEN C.Connectionformat = 1 THEN 'Email'
WHEN C.Connectionformat = 2 THEN 'Website'
WHEN C.ConnectionFormat =3 THEN 'Others'
END AS ConnectionType,
C.Value AS Information
FROM Connection C


OutPut::

Phone 121212
Email a@annet.com
Website www.annet.com
Phone 765432
Email b@annet.com
Phone 667877
Email b@annet.com

 

Friday, March 2, 2012

WCF Service Errors

ERROR 1:TimeoutException

The request channel timed out while waiting for a reply after 00:00:59.9970000. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout.
SOLUTION:
1)A call to clientservice.close() will solve the problem.

REFERENCES:
1)
 http://stackoverflow.com/questions/739312/c-sharp-wcf-wcf-stops-responding-after-about-10-or-so-calls-throttling
==================================================================
2)
 why do I have to Close a service Proxy? http://geekswithblogs.net/marcel/archive/2007/05/01/112159.aspx
===============================================================

3)
http://www.codeguru.com/csharp/.net/net_wcf/article.php/c15941/        
StockService.StockServiceClient client = new StockService.StockServiceClient(
              "StockBasicHttpEndpoint", stockServiceUrl);

string StockId = client.GetStockIdByName("MSFT");

//Done with the service, let's close it.
try
{
   if (client.State != System.ServiceModel.CommunicationState.Faulted)
   {
      client.Close();
   }
}
catch (Exception ex)
{
   client.Abort();
}
==================================================
4)http://msdn.microsoft.com/en-us/library/ms735103.aspx
     
CalculatorClient wcfClient = new CalculatorClient();
try
{
    Console.WriteLine(wcfClient.Add(4, 6));
    wcfClient.Close();
}
catch (TimeoutException timeout)
{
    // Handle the timeout exception.
    wcfClient.Abort();
}
catch (CommunicationException commException)
{
    // Handle the communication exception.
    wcfClient.Abort();
}