Thursday, February 9, 2012

Auto generated Numbers in SQL Query

Auto generated Numbers in SQL Query

create table CountryMaster
(
id int identity(1,1),
cityname varchar(50),
countryname varchar(50)
)

select * from CountryMaster

insert into CountryMaster values('New Delhi','India')
insert into CountryMaster values('Mumbai','India')
insert into CountryMaster values('Kolkata','India')
insert into CountryMaster values('Chennai','India')

insert into CountryMaster values('London','UK')
insert into CountryMaster values('Amsterdam','UK')
insert into CountryMaster values('Southampton','UK')

insert into CountryMaster values('Washington','US')
insert into CountryMaster values('New York','US')
insert into CountryMaster values('Chicago','US')

insert into CountryMaster values('Canberra','Australia')
insert into CountryMaster values('NSW','Australia')
insert into CountryMaster values('Melbourn','Australia')

insert into CountryMaster values('Islamabad','Pakistan')
insert into CountryMaster values('Karachi','Pakistan')
insert into CountryMaster values('Hyderabad','Pakistan')

select id, cityname, countryname,
ROW_NUMBER() OVER (PARTITION BY [countryName] ORDER BY id) AS Seq
from CountryMaster


Result
-------
.............................................
id cityname countryname Seq
.............................................
27 Canberra Australia 1
28 NSW Australia 2
29 Melbourn Australia 3

17 New Delhi India 1
18 Mumbai India 2
19 Kolkata India 3
20 Chennai India 4

30 Islamabad Pakistan 1
31 Karachi Pakistan 2
32 Hyderabad Pakistan 3

21 London UK 1
22 Amsterdam UK 2
23 Southampton UK 3

24 Washington US 1
25 New York US 2
26 Chicago US 3
.............................................

select id, cityname, countryname,
ROW_NUMBER() OVER (ORDER BY id) AS Seq
from CountryMaster

Result
-------
.............................................
id cityname countryname Seq
.............................................
17 New Delhi India 1
18 Mumbai India 2
19 Kolkata India 3
20 Chennai India 4
21 London UK 5
22 Amsterdam UK 6
23 Southampton UK 7
24 Washington US 8
25 New York US 9
26 Chicago US 10
27 Canberra Australia 11
28 NSW Australia 12
29 Melbourn Australia 13
30 Islamabad Pakistan 14
31 Karachi Pakistan 15
32 Hyderabad Pakistan 16
.............................................


select id, cityname, countryname,
ROW_NUMBER() OVER(order by id) AS Seq
from CountryMaster order by cityname

List of few CMMi level 5 companies in HYD, BLR, Pune

---
HYD
---
TCS
WIPRO
MAHINDRA SATYAM
INFOSYS
HCL
COGNIZANT
UHG
WELLSFARGO FINANCE COMPANY
SIERRA ATLANTIC
INTELLIGROUP
SEMANTICSPACE
IGATE
KEANE
INFOTECH

DELL
ORACLE
ADP
CGI
DELOITTE
VIRTUSA
CSC
CONVERGYS
ACCENTURE
CAPGEMNI
POLARIS
SONATA
JDA
NCR
KENEXA

----
BLR
----
ITC INFOTECH
TESCO
HP
MPHASIS
L & T INFOTECH
COVANSYS
INTEL
ABB
MCAFEE
FIC
SASKEN
LOGICA
SAPIENT
THOMSON REUTERS
PHILIPS

IBM
HONEYWELL
PEROT SYSTEMS
MINDTREE
JP MORGAN

-----
PUNE
-----
TECH MAHINDRA
SYNTEL
BLUE STAR INFOTECH
MASTEK
HEXAWARE
3I INFOTECH (ICICI)

Google maps - code to display image from URL

protected void Page_Load(object sender, EventArgs e)

{

if (!(Page.IsPostBack))

{

// to get the image stream

//http://www.greywyvern.com/code/php/binary2base64

// google maps image

// http://code.google.com/apis/maps/documentation/staticmaps/

//// working url

////string GoogleURL = "http://maps.google.com/maps/api/staticmap?sensor=false&zoom=0&size=320x169&maptype=roadmap";

///////// ++++++++++++++++++++++++++++++++++++++

// working

//string GoogleURL = "http://maps.google.com/maps/api/staticmap?sensor=false&zoom=12&size=480x313&maptype=roadmap¢er=52.4871716,1.7153936&markers=52.4871716,1.7153936";

// not working

//string GoogleURL = "http://maps.google.com/maps/api/staticmap?sensor=false&zoom=12&size=480x313&maptype=roadmap¢er=51.5017821,-0.1154330&markers=51.5017821,-0.1154330";

// old

//string GoogleURL = "http://maps.google.com/maps/api/staticmap?sensor=false&zoom=0&size=320x169&maptype=roadmap";

string GoogleURL = "http://maps.google.com/maps/api/staticmap?sensor=false&zoom=12&size=480x313&maptype=roadmap¢er=-33.8389280,151.2085890&markers=-33.8389280,151.2085890&format=jpg";


/////////////////////////////////////string GoogleURL1 = HttpUtility.UrlDecode("http%3a%2f%2fmaps.google.com%2fmaps%2fapi%2fstaticmap%3fsensor%3dfalse%26zoom%3d0%26size%3d320x169%26maptype%3droadmap");

string strResponse = string.Empty;


WebRequest objWebRequest;

objWebRequest = WebRequest.Create(GoogleURL);

WebProxy proxy = new WebProxy();

objWebRequest.Proxy = proxy;

objWebRequest.UseDefaultCredentials = true;

objWebRequest.Proxy.Credentials = CredentialCache.DefaultCredentials;

objWebRequest.ContentType = "Content-Type: image/png";

StreamReader loResponseStream = new StreamReader(objWebRequest.GetResponse().GetResponseStream(), Encoding.UTF8);

var bytes = default(byte[]);

using (var memstream = new MemoryStream())

{

var buffer = new byte[512];

var bytesRead = default(int);

while ((bytesRead = loResponseStream.BaseStream.Read(buffer, 0, buffer.Length)) > 0)

{

memstream.Write(buffer, 0, bytesRead);

}

bytes = memstream.ToArray();

}

image1.Attributes["src"] = "data:image/png;base64," + Convert.ToBase64String(bytes);

//Response.Clear();

//Response.ContentType = "Image/png";

//Response.BinaryWrite(bytes);

}

}

LINQ SQL Injection

http://msdn.microsoft.com/en-us/library/bb399403.aspx

http://csharp-codesamples.com/2009/05/preventing-sql-injection-using-linq/

reading data through Excel

private DataTable ReadExcelData(string strFilePath, string strFileType)

{

DataTable dt = new DataTable();

try

{

if (strFileType.ToLower().Contains("xls") || strFileType.ToLower().Contains("xlsx"))

{

OleDbCommand excelCommand = new OleDbCommand();

OleDbDataAdapter excelDataAdapter = new OleDbDataAdapter();

// for office 2003 and prior versions

//////////string excelConnStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + strFilePath + "; Extended Properties =Excel 8.0;";

/////// for office 2007 onwards and prior versions

string excelConnStr = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + strFilePath + "; Extended Properties =Excel 12.0;";

// Microsoft.Jet.OLEDB.4.0 driver is only for uploading Microsoft-Excel 2003 and earlier versions.

OleDbConnection excelConn = new OleDbConnection(excelConnStr);

excelConn.Open();

DataTable dtSheetName = excelConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

if (dtSheetName != null && dtSheetName.Rows.Count > 0)

{

string strSheetName = dtSheetName.Rows[0]["TABLE_NAME"].ToString();//gives first sheetname in the excel

excelCommand = new OleDbCommand("SELECT * FROM [" + strSheetName + "]", excelConn);//excelCommand = new OleDbCommand("SELECT * FROM [Sheet1$]", excelConn);

excelDataAdapter.SelectCommand = excelCommand;

excelDataAdapter.Fill(dt);

}

excelConn.Close();

}

}

catch (Exception objEx)

{

throw objEx;

}

finally

{

//Delete the saved file from server path after reading the data from the path.Because it is uploaded from client machine to database.We are saving to server to avoid errors.After process we are deleting here.

if (File.Exists(strFilePath))

File.Delete(strFilePath);

}

return dt;

}

shivprasad koirala URLS on WCF

http://www.codeproject.com/KB/WCF/WCFTransactions.aspx

http://www.codeproject.com/KB/WCF/WCFFAQPart5.aspx

http://www.codeproject.com/KB/aspnet/WCF.aspx

http://www.codeproject.com/KB/aspnet/WCFPart2.aspx

http://www.codeproject.com/KB/WCF/WCFFAQPart3.aspx

http://www.codeproject.com/KB/WCF/WCFTracingFAQ.aspx

sending emails through c# asp.net

web.config entry

<system.net>
<mailSettings>
<smtp from="yoursenderemail@corporate.com">
<network host="hostname" port="25" password="Password"
userName="PASSPORT2" defaultCredentials="false" /> </smtp>
</mailSettings>
</system.net>

Note: 1) Make sure from address domain name
2) IP address, port number should be valid

c# code

SmtpSection mailSettings = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection;
MailMessage MyMessage = new MailMessage();

string sendTo = this.txtEmailHard.Text;
string sendFrom = mailSettings.From;
string sendMessage = "hello now the time is : " + DateTime.Now.ToLongDateString();
MyMessage.To.Add(sendTo);
MyMessage.From = new MailAddress(sendFrom);
MyMessage.Subject = "Hi Welcome to eProfile";
MyMessage.Body = sendMessage;
MyMessage.IsBodyHtml = true;

this.lblComment.Text = mailSettings.Network.Host + " " + mailSettings.Network.Port;

SmtpClient emailClient = new SmtpClient(mailSettings.Network.Host, mailSettings.Network.Port);
if (mailSettings.Network.DefaultCredentials)
{
emailClient.UseDefaultCredentials = true;
}
else
{
emailClient.Credentials = new System.Net.NetworkCredential(mailSettings.Network.UserName, mailSettings.Network.Password);
}

emailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
emailClient.Send(MyMessage);
return;
}
catch (SmtpException smtpx)
{
throw smtpx;
}
catch (Exception ex)
{
throw ex;
}

sending emails through c# asp.net code

web.config entry




userName="PASSPORT2" defaultCredentials="false" />




Note: 1) Make sure from address domain name
2) IP address, port number should be valid

c# code

SmtpSection mailSettings = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection;
MailMessage MyMessage = new MailMessage();

string sendTo = this.txtEmailHard.Text;
string sendFrom = mailSettings.From;
string sendMessage = "hello now the time is : " + DateTime.Now.ToLongDateString();
MyMessage.To.Add(sendTo);
MyMessage.From = new MailAddress(sendFrom);
MyMessage.Subject = "Hi Welcome to eProfile";
MyMessage.Body = sendMessage;
MyMessage.IsBodyHtml = true;

this.lblComment.Text = mailSettings.Network.Host + " " + mailSettings.Network.Port;

SmtpClient emailClient = new SmtpClient(mailSettings.Network.Host, mailSettings.Network.Port);
if (mailSettings.Network.DefaultCredentials)
{
emailClient.UseDefaultCredentials = true;
}
else
{
emailClient.Credentials = new System.Net.NetworkCredential(mailSettings.Network.UserName, mailSettings.Network.Password);
}

emailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
emailClient.Send(MyMessage);
return;
}
catch (SmtpException smtpx)
{
throw smtpx;
}
catch (Exception ex)
{
throw ex;
}

Thursday, February 2, 2012

multiple end points scenario

---------------
Project Manager
---------------
Method 1
Method 2
Method 3
Method 4

---------------
Project Leader
---------------
Method 5
Method 6
Method 7

---------
Developer
---------
Method 8
Method 9
Method 10


End points - PMEndPoint - A B C
End points - PLEndPoint
End points - DevEndPoint

Address - http://localhost/MobileApps/Service1.svc
Binding - WSHttpBinding
Contract - IPMService

Address - http://localhost/MobileApps/Service1.svc
Binding - WSHttpBinding
Contract - IPLService

Address - http://localhost/MobileApps/Service1.svc
Binding - WSHttpBinding
Contract - IDevService

public interface IPMService
{

Method 1
Method 2
Method 3
Method 4

}

public interface IPLService
{

Method 5
Method 6
Method 7

}

public interface IDevService
{

Method 8
Method 9
Method 10

}

what is data center

A data center is a facility used to house computer systems and associated components, such as telecommunications and storage systems. It generally includes redundant or backup power supplies, redundant data communications connections, environmental controls (e.g., air conditioning, fire suppression) and security devices.

Tier Level 1 - 99.671% availability
Tier Level 2 - 99.741% availability
Tier Level 3 - 99.982% availability
Tier Level 4 - 99.995% availability

IT operations are a crucial aspect of most organizational operations. One of the main concerns is business continuity; companies rely on their information systems to run their operations.

The boom of data centers came during the dot-com bubble. Companies needed fast Internet connectivity and nonstop operation to deploy systems and establish a presence on the Internet.

Installing such equipment was not viable for many smaller companies. Many companies started building very large facilities, called Internet data centers (IDCs), which provide businesses with a range of solutions for systems deployment and operation.

New technologies and practices were designed to handle the scale and the operational requirements of such large-scale operations. These practices eventually migrated toward the private data centers, and were adopted largely because of their practical results.

WCF Instance

WCF instance dictates how the objects are created while WCF concurrency dictates how many requests can be handled by the WCF objects.


WCF instancing - per call, per session and single
WCF concurrency - single , multiple, reentrant


Single: -
==============
1) A single request has access to the WCF service object at a given moment of time.
2) So only one request will be processed at any given moment of time. The other requests have to wait until the request processed by the WCF service is not completed.

Multiple: -
==============
1) In this scenario multiple requests can be handled by the WCF service object at any given moment of time.
2) In other words request are processed at the same time by spawning multiple threads on the WCF server object. So you have great a throughput here but you need to ensure concurrency issues related to WCF server objects.

Reentrant: -
==============
1) A single request thread has access to the WCF service object,
2) but the thread can exit the WCF service to call another WCF service or can also call WCF client through callback and reenter without deadlock.

Note: By default WCF services are 'Single' concurrency and instancing mode ‘per call’.



Per call
==============

• You want a stateless services
• Your service hold intensive resources like connection object and huge memory objects.
• Scalability is a prime requirement. You would like to have scale out architecture.
• Your WCF functions are called in a single threaded model.

Per session
==============

• You want to maintain states between WCF calls.
• You want ok with a Scale up architecture.
• Light resource references

Single
==============

• You want share global data through your WCF service.
• Scalability is not a concern.