简体   繁体   中英

C# ConnectionString

How can I use the connectionString defined in APP.Config in datasource wizard? I can do it in a web application easily but I can't do it in non web application program.

You need to use the bellow syntax to retrive the connection string from app.config

string conStr = ConfigurationManager.ConnectionStrings["NorthwindConnection"].ConnectionString;

Then use the bellow syntax.Oh!first of all you need to add using System.Configuration; name space

 Connection = new SqlConnection(conStr);

Try playing with ConfigurationManager class. This should do:

string myConnString = ConfigurationManager.ConnectionStrings["myConnStringName"].ConnectionString;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM