Where to add connection string in web .config file of ASP.Net - Starter Asp.Net Tutorials.



It is a good practice to store the connection string for your application in a config file rather than as a hard coded string in your code. The way to do this differs between .NET 2.0 and .NET 3.5 (and above). This article covers .NET 3.5 and above.


In the Previous articles i explained how to integrate ckeditor with asp.nethow to upload image to the server or application using Ckeditor , how to change or set width of ckeditor textbox area using asp.nethow to set or change height of Ckeditor textbox area using ASP.Netintegrate custom image uploader control with ckeditor using asp.net, how to add asp.net membership tables to the existing database  and many more about Asp.Net.

Connection string in .NET 3.5 (and above) config file

Step 1.

Open your web.config File.

Step 2.

Do not use appsettings in web.config. Instead use the connectionStrings section in web.config.

Step 3.

Locate <configuration> tab and put the connection string between them like below.

    <add name="database_con" connectionString="Data Source=MY-PC\SQLEXPRESS;Initial Catalog=DB1;Integrated Security=True" providerName="System.Data.SqlClient"/>

You have successfully created your connection string.

In above config file database_con is a connection string. It is separated from source code because you can change the config file any time and don’t need to compile the source code.

NOTE : Always store the connection string in a config file. It's not any harder once you get used to it and you will benefit from it as it is much easier to change connection string properties when your application is in production.

Give your Valuable Comments.
comments powered by Disqus
Follow me on twitter
About Me
Harpreet Singh
I began programming with C++ when i was 17. Then at the middle of my study .NET came. Then I began to read C# and VB.NET. By the time i learnt SQL and ASP.NET, and developed some websites such as news portals that are active now. Currently i am running my own Software company.
More Articles