访问类中的数据库时,app.config给出错误

问题描述:

先生

string connectionString =(string)ConfigurationSettings.AppSettings["SanaSoh"];


该行在页面上正确运行,但是在类中运行时会给我一个错误.有人请给我一个app.confing文件的想法.我使用app.cofing文件并提供了数据库的路径,但是我无法从该类内部访问数据库.
请给我一个想法,如何通过使用app.config或直接在win.config的类中使用数据库.

谢谢!


This line runs correctly on page, but when run in a class it gives me an error. Somebody please give me an idea for app.confing file. I use app.cofing file and give path of my database, but I don''t get access to database from within the class.
Please give me an idea how to use database in a class from win.config by using app.config or directly.

Thank you!

ConfigurationSettings自.NET 2.0发布以来已经过时.您应该使用 ConfigurationManager [ ConnectionStrings [
ConfigurationSettings has been obsolete since .NET 2.0 was released. You should be using the ConfigurationManager[^]. Use the ConnectionStrings[^] property to get a database connection string from the app.config file.