Connection String in c#.net

A

Atul Rane

I am declareing my connection string in web.config file like that ;

<connectionStrings>
<add name ="SQLConnectionString" connectionString ="Persist Security
Info=False;User ID=sa;password=P@ssw0rd;Initial Catalog=Aperio;Data
Source=OPTRA-2003"/>
</connectionStrings >

Know i want to access this connection string in my Class.
How i can get this connection string in my Class.
I added reference System.Configuration but still i am unable to get
ConfigurationManager.ConnectionString[""].connectionstring.
 
P

Peter Morris

01: Add System.Configuration.dll to your references
02:
string cs =
System.Configuration.ConfigurationManager.ConnectionStrings["SQLConnectionString"];
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top