473,399 Members | 3,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

The ConnectionString property has not been initialized

hi
I am doing project under entire architecture in ASP.Net ,, But i am getting coonection error while running the program

connection at webconfig is below:
Expand|Select|Wrap|Line Numbers
  1.   <appSettings>
  2.  
  3.     <add key="Myconn" value="server=.;uid=;pwd=;Initial Catalog=tempdb;Integrated Security=true"/>
  4.       </appSettings >
  5.  
my code on calling connection is

Expand|Select|Wrap|Line Numbers
  1. using System.Web;
  2. using System.Web.Security;
  3. using System.Web.UI;
  4. using System.Web.UI.WebControls;
  5. using System.Web.UI.WebControls.WebParts;
  6. using System.Web.UI.HtmlControls;
  7. using System.Data.SqlClient;
  8.  
  9. /// <summary>
  10. /// Summary description for clsvarDeclaration
  11. /// </summary>
  12. public class clsvarDeclaration
  13. {
  14.     private static SqlConnection con = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["Myconn"]);
  15.  
  16.  
  17.     public clsvarDeclaration()
  18.     {
  19.         //
  20.         // TODO: Add constructor logic here
  21.         //
  22.     }
  23.  
  24.     public static SqlConnection connection
  25.     {
  26.         get
  27.         {
  28.             return con;
  29.         }
  30.         set
  31.         {
  32.             con = value;
  33.         }
  34.     }
  35. }
  36.  
but it shows error: The ConnectionString property has not been initialized


Any suggetions most Welcome
Feb 25 '08 #1
1 707
Plater
7,872 Expert 4TB
Well, I am not sure why that doesnt work, but I have used this with success:
Expand|Select|Wrap|Line Numbers
  1. private static AppSettingsReader ap = new AppSettingsReader();
  2.  
  3. public static string ConnectionString
  4. {
  5.    get
  6.    {
  7.       return ap.GetValue("mycon", typeof(string)).ToString();
  8.    }
  9. }
  10.  
ALSO: On the connection string you have (I assume you removed those values for safety reasons), using Integrated Security=true negates the uid and pwd statements, which are not even valid statements for SqlConnection:
http://www.connectionstrings.com/?carrier=sqlserver
Feb 25 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: TPSreport | last post by:
I log on to the cookieless application, work within it for awhile, jump to a URL outside the application, then return to the application. As soon as a db call is required, I get the error below. ...
2
by: Kamal | last post by:
Hi everyone, I've created a user control that calls some method from a class that set the connection string, the connection string is stored in the App.Config file. When i try to add that...
5
by: josephrthomas | last post by:
hi...i am getting a error here...saying : **quote** The ConnectionString property has not been initialized. Description: An unhandled exception occurred during the execution of the current web...
6
by: Tony | last post by:
Dear All, When I run an example program on the http://www.dotnetjunkies.com/quickstart/util/srcview.aspx?path=/quickstart/aspplus/samples/webforms/data/datagrid1.src&file=VB\datagrid1.aspx&font=3 ...
10
by: Laura K | last post by:
Tried all kinds of things. I get the error. The ConnectionString property has not been initialized. Any help appreciated. ...
5
by: Kent Johnson | last post by:
Hi all, I have accidentally deleted my web.config file so I'll have to recreate it. I have tried this in my Web.config file: <configuration> <appSettings> <add key="ConnectionString"...
2
by: tshad | last post by:
I am trying to create an application in my VS 2002 application. I took some of the code from my web page where it works fine. I can connect fine from my Sql Query Analyser to both my local Sql...
4
by: QC | last post by:
Hi, this morning found that my Service had crashed, and the error was "Exception Details: System.InvalidOperationException: The ConnectionString property has not been initialized". I have no...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.