473,396 Members | 2,026 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,396 software developers and data experts.

getting error The ConnectionString property has not been initialsed

Hi
I want to declare a coonectionstring in winapps as declared in web.config file in webapps.
I declare that in app.config as follows
Expand|Select|Wrap|Line Numbers
  1. <connectionStrings>
  2.         <add name="ABC_Enterprises_.Properties.Settings.ABCEnterpriseDataConnectionString"
  3.             connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ABCEnterpriseData.mdf;Integrated Security=True;User Instance=True"
  4.             providerName="System.Data.SqlClient" />
  5.     </connectionStrings>
  6.  
but now i dnt know how to call this in program.

Can you please help me
Thanks
Mar 8 '08 #1
1 1171
hello
I am using sql for the first time with dotnet.
I had created the database and directly using .net by choosing sqldatabase from new item
and in the form i write the following code. My code is :
Expand|Select|Wrap|Line Numbers
  1.  string constr = ConfigurationSettings.AppSettings["ConnectionString1"];
  2.                 SqlConnection conn = new SqlConnection(constr);
  3.                 conn.Open();
  4.                 SqlCommand cmd = new SqlCommand();
  5.                 string str = "insert into OwnerDetails(OwnerId,FirstName,MiddleName,LastName,Age,Occupation,Address,City,State,PinCode,TelNo,Others) values(1,@FirstName,@MiddleName,@LastName,@Age,@Occupation,@Address,@City,@State,@PinCode,@TelNo,@Others)";
  6.                 cmd.Connection = conn;
  7.                 cmd.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = txtFirstName.Text;
  8.                 cmd.Parameters.Add("@MiddleName", SqlDbType.VarChar).Value = txtMName.Text;
  9.                 cmd.Parameters.Add("@LastName", SqlDbType.VarChar).Value = txtLastName.Text;
  10.                 cmd.Parameters.Add("@Age", SqlDbType.Int).Value = txtAge.Text;
  11.                 cmd.Parameters.Add("@Occupation", SqlDbType.VarChar).Value = txtOccupation.Text;
  12.                 cmd.Parameters.Add("@Address", SqlDbType.VarChar).Value = txtAddress.Text;
  13.                 cmd.Parameters.Add("@City", SqlDbType.VarChar).Value = cmbCity.SelectedItem.ToString();
  14.                 cmd.Parameters.Add("@State", SqlDbType.VarChar).Value = cmbState.SelectedItem.ToString();
  15.                 cmd.Parameters.Add("@PinCode", SqlDbType.VarChar).Value = txtPincode.Text;
  16.                 cmd.Parameters.Add("@TelNo", SqlDbType.VarChar).Value = txtTelNo.Text;
  17.                 cmd.Parameters.Add("@Others", SqlDbType.VarChar).Value = txtOthers.Text;
  18.  
  19.                 cmd.CommandText = str;
  20.                 cmd.CommandType = CommandType.Text;
  21.                 cmd.ExecuteNonQuery();
  22.                 conn.Close();
  23.  
  24. App.config files setting:
  25. <add name="ConnectionString1"
  26.             connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\NGEnterpriseData.mdf;Integrated Security=True;User Instance=True"
  27.             providerName="System.Data.SqlClient" />
  28.  
  29.  
But after when i ran the application i got the following error
The ConnectionString property has not been initialsed

Please suggest me why this error occurs and can i modify it
Mar 8 '08 #2

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

Similar topics

0
by: Dotnetified | last post by:
Reposting after about 2 weeks of no response ... thanks if you can help... ---------------------------------------------------------------------------- -------------- To anyone who thinks they...
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 ...
6
by: Alixx Skevington | last post by:
OK why does the following code work in a Windows form with a crystal report viewer but not in a webform. I get the usual CrystalReports.EngineLogONException logon Failed when this is called in...
2
by: Sam | last post by:
I'm trying to create authentication for username and password but encounter below error message: Error Message ----------------------- The ConnectionString property has not been initialized....
1
by: John Wilhelm | last post by:
I'm having a problem in by VB.net 2005 application. When i try to get a node from my app.config file the node come back with "nothing". The xmldocment loads OK, but I can't retrive a node. The...
0
by: manicmax | last post by:
Hey I have a question for u I am taking connection string from IIS like this readonly string dataSource3 =ConfigurationManager.ConnectionStrings.ConnectionString; and using this dataSource3 ...
0
by: TG | last post by:
Hi! Once again I have hit a brick wall here. I have a combobox in which the user types the server name and then clicks on button 'CONNECT' to populate the next combobox which contains all the...
0
by: aboutjav.com | last post by:
Hi, I need some help. I am getting this error after I complete the asp.net register control and click on the continue button. It crashed when it tries to get it calls this Profile property ...
2
by: Andrew Cooper | last post by:
Greetings, I've got a website that has several pages with DataGrid controls on them. The controls are bound to Object Datasources. On one of the pages I keep getting a "Timeout expired. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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.