Wednesday, August 17, 2011

MAC ID Generating In C#.NET

Step 1:

Go to the solution Explorer--> Right Click --> Add Refrence --> System.Management

Step 2:

Add 2 NameSpaces :
1).using System.Management;
2).using System.Management.Instrumentation;

Step 3:

//Create object for management class
ManagementClass mc=newManagementClass("Win32_NetworkAdapterConfiguration");

Step 4:
//management object collection represent all collections from managemnet class                                               
ManagementObjectCollection moc = mc.GetInstances();
string MACAddress = String.Empty;
foreach (ManagementObject mo in moc)
 {
if(MACAddress == String.Empty) 
// only return MAC Address from first card            
 {
if ((bool)mo["IPEnabled"] == true)
 MACAddress = mo["MacAddress"].ToString(); 
 }
mo.Dispose();     
}         
//after every 2 digits it returns ":"      
 MACAddress = MACAddress.Replace(":", "");                       MessageBox.Show(MACAddress);

Tuesday, August 9, 2011

Stored Procedure Optimzation tips




1).Use NOCOUNT:

Include the SET NOCOUNT ON statement into your stored procedures to stop the message indicating the number of rows affected by a Transact-SQL statement.

2).Use return values:

Consider returning the integer value as an RETURN statement instead of an integer value as part of a recordset

3).Try to avoid using temporary tables inside your stored procedure.

4).Use SQL Server Profiler to determine which stored procedures has been recompiled too often.

5).Use sp_executesql stored procedure instead of temporary stored procedures.

Saturday, August 6, 2011

Difference between stored procedure and function


1) Procedure can return zero or n values whereas function can return one value which is mandatory.

2) Procedures can have input, output parameters for it whereas functions can have only input parameters.

3) Procedure allows select as well as DML statement in it whereas function allows only select statement in it.

4) Functions can be called from procedure whereas procedures cannot be called from function.

5) Exception can be handled by try-catch block in a procedure whereas try-catch block cannot be used in a function.

6) We can go for transaction management in procedure whereas we can't go in function.

7) Procedures cannot be utilized in a select statement whereas function can be embedded in a select statement.