asp.net - How to set the connection string from app.config please -


i have done till , don't know how call connection string console application app.config

<add name="virgoplaza"       connectionstring="data source=jean-daniel\sqlexpress;initial catalog=virgoplaza;integrated security=true"      providername="system.data.sqlclient" /> 

can please?

first add reference system.configuration. in solution explorer, right click on references, add references.

add reference system.configuration manager.

enter image description here

then access connection string like:

var connectionstrings = system.configuration                             .configurationmanager.connectionstrings; var yourconnectionstring = connectionstrings["virgoplaza"]; 

assuming have stored connection string in app.config like:

<?xml version="1.0"?> <configuration>   <connectionstrings>     <clear />     <add name="virgoplaza" connectionstring="data source=jean-daniel\sqlexpress;initial catalog=virgoplaza;integrated security=true"             providername="system.data.sqlclient" />   </connectionstrings> </configuration> 

vb.net equivalent be:

dim cons string = system.configuration                         .configurationmanager                         .connectionstrings("virgoplaz").connectionstring 

you may see: connection strings , configuration files


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -