943,102 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 2497
  • ASP.NET RSS
Jan 26th, 2010
0

How create connectionstring in web.config file using c#?

Expand Post »
Hai,I am trying to connection using web.confing in connectionstring element
and i have written below code in connectionstring element in
ASP.NET Syntax (Toggle Plain Text)
  1.  
  2. <connectionStrings>
  3. <add name="DB1" connectionString="Data Source=DEV5\\SQLEXPRESS;Initial Catalog=icondatabase;Integrated Security=True" />
  4. </connectionStrings>
And in the .aspx.cs file (in Load_page)i have written below code
ASP.NET Syntax (Toggle Plain Text)
  1.  
  2. string connection= ConfigurationManager.ConnectionStrings["DB1"].ToString();
  3. SqlConnection cn = new SqlConnection("connection");
while i compiled page it give the error:
"
ArgumentExeption was Unhandled by User Code
Format of the initialization string does not conform to specification starting at index 0."

any body plz help me......
Similar Threads
Reputation Points: 9
Solved Threads: 0
Junior Poster in Training
Pari13 is offline Offline
59 posts
since Jan 2010
Jan 26th, 2010
0
Re: How create connectionstring in web.config file using c#?
Remove double quotes.

ASP.NET Syntax (Toggle Plain Text)
  1. ...
  2. SqlConnection cn = new SqlConnection(connection);
Moderator
Reputation Points: 2134
Solved Threads: 1227
Posting Genius
adatapost is offline Offline
6,524 posts
since Oct 2008
Jan 26th, 2010
0
Re: How create connectionstring in web.config file using c#?
Click to Expand / Collapse  Quote originally posted by adatapost ...
Remove double quotes.

ASP.NET Syntax (Toggle Plain Text)
  1. ...
  2. SqlConnection cn = new SqlConnection(connection);
thanks it run....successfully.
Reputation Points: 9
Solved Threads: 0
Junior Poster in Training
Pari13 is offline Offline
59 posts
since Jan 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: receive email to our address submitted by the user
Next Thread in ASP.NET Forum Timeline: SQL Connection from web.config





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC