How to change from Windows Authentication to SQL Server Authentication for SQLExpress 2005

While installing SQL Express, we have to specify Sql Authentication mode and specify password for sa otherwise Windows Authentication mode being enabled (it is a default mode). To change mode we have to perform the following steps to change to SQL Server Authentication, using the sa (system administrator) account

1) Enable SQL Server Authentication by executing: "ALTER LOGIN sa ENABLE", or by using the Microsoft SQL Server Management Studio Express application.

2) Change/set the password for the sa account by executing: "ALTER LOGIN sa WITH PASSWORD = 'yourpassword'"

3) Stop the SQL Server service

4) Open regedit, go to the "HKLMSoftwareMicrosoftMSSqlserverMSSqlServer" entry and set the LoginMode value to 2.

goto start->run-> type regedit
goto search window find LoginMode
it will show in sqlserver entry set LoginMode 2


HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.1\MSSQLServerLoginMode 2

5) Restart the SQL Server service

Email through SMTP Client (ASP.NET/C#)

Yes,it is easy to send email in .Net application through SMTP Client.First you have add
using System.Net.Mail; namespace should be added in your application.

using System.Net.Mail; //namespace

SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);

System.Net.NetworkCredential mailAuthentication = new System.Net.NetworkCredential("yourmailid@gmail.com", "yourgmailpassword");

MailMessage message = new MailMessage();
try
{

MailAddress fromAddress = new MailAddress("fromemailid@gmail.com"iyen");
// Enable SSLsmtpClient.EnableSsl = true;


smtpClient.UseDefaultCredentials = false;

smtpClient.Credentials = mailAuthentication;
////From address will be given as a MailAddress Object
message.From = fromAddress;
// To address collection of MailAddressmessage.To.Add(Togmail@gmail.com);

message.Subject = "Test Mail from C# Application";

message.IsBodyHtml = false;
//// Message body content
message.Body = "Nice C# function"
//// Send SMTP mail
smtpClient.Send(message);
MessageBox.Show("Email successfully sent.");
}
catch (Exception ex)
{

MessageBox.Show("Send Email Failed");
}


Before run this program check your are given
Vaild yourmailid@gmail.com , yourgmailpassword and vaild Togmail@gmail.com..

Connection Pooling in .NET

Acquiring a connection takes a short, but definite amount of time. In web application in which requests are being handled efficiently,connections will be opened and closed endlessly as new requests are processed. In this environment, a small overhead required to establish a connection can become significant and limit the scalability of the system.

One solution is connection pooling. Connection pooling is the practise of keeping a permanent set of open database connections to be shared by the sessions that uses the same data sources. This avoids the need to create and destroy connection all the time.

When client requests the connection by calling Open(), it's served directly fro the available pool, rather than re-created. When the client release the connections by calling Close() or Dispose(), it's not discarded but returned to the pool to serve next request.

You can able to configure connection pool setting in connection strings. Various connection pool settings are as follows

a. Max Pool Size : The maximum number of connections allowed in the pool. If the maximum pool size size has been reached, any further attempts wait until a connection become available.(An error is raised if the connection timeout value elapses before a connection available.)

b. Min Pool Size : The minimum number of connection always retained in the pool(default as 0). This number of connections will be created when the first connection is opened, leading minor delay for the first request.

c. Pooling : When true (the default), the connection is drawn from the appropriate pool or, if necessary, is created and added to the appropriate pool.

d. Connection Life Time : Connections is returned to the pool and its creation time is older than the specified lifetime.

Example of connection string that set a minimum pool size:

string Connectionstring = "Data Source = localHost; Initial Catalog = master; Integrated Security = SSPI; Min Pool Size = 10;Max Pool Size=60";

SqlConnection con = new SQlConnection(Connectionstring);

//Get the connection from the pool( if it exists)
//or create the pool with 10 connections(if it doesn't)
con.Open();

//Return connection to the pool.
con.Close();

Memory Usage Reduces On Application Minimize

Everseen memory usage of a program go down as soon as it’s minimized. Well how to achieve this programmatically(VB.NET and C#).

Using the anyone of the following API function we can reduce memory usage.
SetProcessWorkingSetSize( GetCurrentProcess(), -1, -1 );
or
EmptyWorkingSet( GetCurrentProcess() );

Sample Code:

C#:
public class MemoryManagement
{

[DllImport("kernel32.dll")]
public static extern bool SetProcessWorkingSetSize( IntPtr proc, int min, int max );

public void ReleaseMemory()
{

GC.Collect() ;
GC.WaitForPendingFinalizers() ;
if(Environment.OSVersion.Platform == PlatformID.Win32NT)
{
SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1) ;
}

}

}
VB.NET :

public class MemoryManagement

Private Declare Auto Function SetProcessWorkingSetSize Lib "kernel32.dll" (ByVal procHandle As IntPtr, ByVal min As Int32, ByVal max As Int32) As Boolean

Friend Sub ReleaseMemory()

Try
GC.Collect()
GC.WaitForPendingFinalizers()
If Environment.OSVersion.Platform = PlatformID.Win32NT Then
SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1)
End If

Catch

End Try
End Sub

end class

Delete Vs Truncate(SQL Server)

• Delete table is a logged operation, so the deletion of each row gets logged in the transaction log, which makes it slow.

• Truncate table also deletes all the rows in a table, but it won’t log the deletion of each row, instead it logs the de-allocation of the data pages of the table, which makes it faster. Of course, truncate table cannot be rolled back.

• Truncate table is functionally identical to delete statement with no “where clause” both remove all rows in the table. But truncate table is faster and uses fewer system and transaction log resources than delete.

• Truncate table removes all rows from a table, but the table structure and its columns, constraints, indexes etc., remains as it is.

• In truncate table the counter used by an identity column for new rows is reset to the seed for the column.

• If you want to retain the identity counter, use delete statement instead.

• You cannot use truncate table on a table referenced by a foreign key constraint; instead, use delete statement without a where clause.

• Truncate table cannot activate a trigger(Any trigger created aganist Delete operation).

• Truncate table may not be used on tables participating in an indexed view.