Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

C# - The Connectionstring Property has Not been Initialized in Asp.net

Feb 25, 2015
Introduction:

Here I will explain how to solve the problem of “the connectionstring property has not been initialized in asp.net while sending request to connect SQL Server using c#.net, vb.net.

Description:

In previous posts I explained read connection string from web.config file in asp.net, read appsettings from web.config file in asp.net, use multiple web.config files in asp.net with example, encrypt and decrypt connection string in asp.net and many articles relating to solve errors in asp.net, SQL Server, IIS, etc. Now I will explain how to solve the problem of “the connectionstring property has not been initialized in asp.net while sending request to connect SQL Server”.

In web.config file I written connection string like as shown below


<connectionStrings>
<add name="dbconnection" connectionString="Data Source=Suresh;Initial Catalog=Praveendb;Integrated Security=true" providerName="System.Data.SqlClient" />
</connectionStrings>

To get this connection string from web.config file I written code like as shown below


SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["dbconnection"]);
con.Open();

Whenever I try to get connection string from web.config I got error like as shown below


C# - The Connectionstring Property has Not been Initialized in Asp.net

Actually this problem occurred because I added dbconnection string in connectionstrings section in web.config but I am trying to get dbconnection from appsettings section. To fix this problem I changed my connectionstring access code like as shown below


SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString);
con.Open();

Once I changed connection string code it fixes the error.

Another of Getting Error

Sometimes this error occurred because of wrong declaration of connectionstring in web.config file like as shown below


<connectionStrings>
<add name="dbconnection" connectionString="DataSource=Suresh;Initial Catalog=Praveendb;Integrated Security=true" providerName="System.Data.SqlClient" />
</connectionStrings>

If you observe above connection string I used datasource without space “DataSource” that’s wrong correct connection string will be like as shown below


<connectionStrings>
<add name="dbconnection" connectionString="Data Source=Suresh;Initial Catalog=Praveendb;;User ID=test;Password=test" providerName="System.Data.SqlClient" />
</connectionStrings>

I hope it helps you to solve your problem. Happy Coding………

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

0 comments :

Give your Valuable Comments

Other Related Posts

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.