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:
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.
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
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. |
|||
|
|||
1 comments :
using MS Access database and facing {"The ConnectionString property has not been initialized."}
Note: Only a member of this blog may post a comment.