访问类中的数据库时,app.config给出错误 [英] app.config gives error when accessing database in class

查看:84
本文介绍了访问类中的数据库时,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.


这篇关于访问类中的数据库时,app.config给出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆