AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 Best Syntax to Open a SqlConnection in Asp.Net 2.0
Posted by Moderator1 on  1/4/2008 2:48:15 AM 8071 Views
Here is the best method to open a SqlConnection in Asp.Net 2.0

using (SqlConnection conn = new SqlConnection("YourConnectionString"))
{
using (SqlCommand cmd = new SqlCommand("YourCommandString", conn))
{
conn.Open();
cmd.ExecuteNonQuery();
}
}

The above syntax opens and closes the connection along with the SqlCommand itself. Every effective in case of any error occurs in database manipulations.

Post New Tips/Tricks View all Tips/Tricks

Featured Resources:
Easing the Migration to Microsoft SQL Server 2005
There are many business and technological reasons for making the move to SQL Server 2005 and SQL Server 2005 Enterprise Edition. In tandem with 64-bit computing platforms, SQL Server 2005 can boost performance by 30% in certain instances, deliver a better database management structure and bolster infrastructure security.
SearchSAP
The Web's best SAP-specific information resource for enterprise IT professionals.
100% Free Subscription until Stock lost.View complete list.
Sponsored by