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("", 587);

System.Net.NetworkCredential mailAuthentication = new System.Net.NetworkCredential("", "yourgmailpassword");

MailMessage message = new MailMessage();

MailAddress fromAddress = new MailAddress(""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(;

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

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

MessageBox.Show("Send Email Failed");

Before run this program check your are given
Vaild , yourgmailpassword and vaild

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)

//Return connection to the pool.

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 );
EmptyWorkingSet( GetCurrentProcess() );

Sample Code:

public class MemoryManagement

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) ;



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()

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


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.

Update Statement Between Two Tables

"T1" is the table having the fields of id and name. There is another table "T2" having id and PetName with some additional information. Now to update "T1".name with "T2".PetName.
Update query is as follows(condition between two tables),
update T1 set = T2.PetName
from T2
where =

SQL Server - Insert multilingual data in table

You need the N'' syntax only if the string contains characters which are not inside the default code page.

"Best practice" is to have N'' whenever you insert into an nvarchar or ntext column.
"Unicode string constants that appear in code executed on the server, such as in stored procedures and triggers, must be preceded by the capital letter N. This is true even if the column being referenced is already defined as Unicode. Without the N prefix, the string is converted to the default code page of the database.

This may not recognize certain characters.The requirement to use the N prefix applies toboth string constants that originate on the server and those sent from the client."

create table mul (lang nvarchar(200))
insert into mul (lang ) values (N'multilingual unicode strings')
insert into mul (lang ) values (N' தமிழ்'
insert into mul (lang ) values (N' 請提供服務的日期進行')

use nVarChar as the column data type.

How to fix SQL Server Error 3154: The backup set holds a backup of a database other than the existing database.


Use WITH REPLACE while using the RESTORE command.


In this example abc is one database,backup.bak is backup of abc.

How to Recover Suspected Database in SQL Server 2000

If a database is marked suspect it cannot be accessed and hence nothing can be performed in the database. A database can be marked suspect for one of the following reasons,

a.If one or more database files are not available.
b.If the entire database is not available.
c.If one or more database files are corrupted.
d.If a database resource is being held by the operating system.

In order to recover the suspected database, sysdatabases status is modified in master database.Before you do any changes with system table run the following command to enable adhoc changes to the system tables.

use master


sp_configure allow, 1


reconfigure with override


sp_resetstatus ‘DatabaseName


After the procedure is run, immediately disable updates to the system tables:

sp_configure 'allow updates', 0




Then Stop and Restart ALL SQL Server Services.

If the database still goes back into suspect mode, and you can't fix the original problem, and you have no recent backup, then you can get information out of the database by putting it into Emergency Mode. If you do this, extract the data/objects out with DTS and rebuild the database.

The following command to put the database into emergency mode

USE master


sp_configure 'allow updates', 1




UPDATE master..sysdatabases SET status = 32768 WHERE name = 'DatabaseName'


sp_configure allow, 0


Stop and Restart ALL SQL Server Services.

We are now ready to pull whatever data we can out of the tables in the corrupt database. Remember, some tables may be corrupt, thus you may have to play with various T-SQL statements to get the data out. First try DTS using EnterprisesManager.

These are the steps necessary to export data out of the corrupt database into the new:

a. Create a new production DB, or a temp DB, to have a place to export whatever data we can out of the corrupt db.

b. Start a DTS operation by going into EM and drilling down to “Data Transformation Services” … “Local Packages”.

c. Open a NEW DTS package by right-mouse clicking …

d. When DTS opens, choose “Copy SQL Server Objects Task” from the Connection Icons. Enter in a description like “Export Corrupt Data”. Enter in the SA/pass combination as well as the CORRUPT database from the drop-down.

e. Select the “Destination” Tab. ”. Enter in the SA/pass combination as well as the PRODUCTION database from the drop-down.

f. Select the “Copy” Tab. UNCHECK the “Create destination objects” box. UNCHECK the “Copy all objects” box and then Click on the “Select Objects” Button. This brings up the “Select Objects” screen.

g. CHECK ONLY “Show all tables” like shown above. Then check each table that needs to be exported. If ALL tables need to be export, Click on the “Select All” button. Click OK.

h. Click OK again and we are done creating this task. Now we execute the package by Clicking the green arrow on the menu bar.


Localize Date and Time through Specific Culture

The DateTime structure provides methods that allow your applications to perform culture-sensitive operations on a DateTime type. An application can use the DateTimeFormatInfo class to format and display a DateTime type based on culture.

Following sample code displays the date and time in different cultures are as follows,

public void DateFormatDisplay()

//To get the Current culture information
DateTime dt = DateTime.Now;
// Creates a CultureInfo for English in US.
CultureInfo CulInf = new CultureInfo("en-US");
// Creates a CultureInfo for German in Germany.
CulInf = new CultureInfo("de-DE");
Console.WriteLine(dt.ToString("d", CulInf));

// Creates a CultureInfo for English in Great Britan.
CulInf = new CultureInfo("en-GB");
Console.WriteLine(dt.ToString("d", CulInf));

If Current date is 14-Apr-2009 then output of above coding are as follows,


Disable browser "Back" button

To avoid Back function in browser.
You have to write the javascript in body of the Html coding..
In body tag,you have to specify the current page name. Let us consider below pages a 'Dynamic.html',in this example we mention onunload we specified the javascript to locate the same page.
Save this html page as 'Dynamic.html' and find it how it works.

<title>Dyanmic Coding...</title>
<body onunload="javascript:window.location.replace('Dynamic.html')"> </body>
we can apply this approach in Transaction other words Next to Login page.

Script use to Scrolling title in browser.

Script use to Scrolling title in browser.
Place this Javascript inside ur html code,
then u find your title dynamic coding moves from left to right....

<title>Dynamic Coding...</title>
<script language="javascript" defer="defer" type="text/javascript">
<!-- var repeat=0
var title=document.title
var leng=title.length
var start=1
function titlemove()
titl= title.substring(0, start)
if (start==leng+1)
if (repeat==1)
if (document.title)
<body>Dynamic Coding..</body>