954,560 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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

Hai,I am trying to connection using web.confing in connectionstring element
and i have written below code in connectionstring element in

<connectionStrings>
      <add name="DB1" connectionString="Data Source=DEV5\\SQLEXPRESS;Initial Catalog=icondatabase;Integrated Security=True" />
      </connectionStrings>

And in the .aspx.cs file (in Load_page)i have written below code

string connection= ConfigurationManager.ConnectionStrings["DB1"].ToString();
      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......

Pari13
Junior Poster in Training
59 posts since Jan 2010
Reputation Points: 9
Solved Threads: 0
 

Remove double quotes.

...
 SqlConnection cn = new SqlConnection(connection);
__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

Remove double quotes.

...
 SqlConnection cn = new SqlConnection(connection);

thanks it run....successfully.

Pari13
Junior Poster in Training
59 posts since Jan 2010
Reputation Points: 9
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You