当前位置:网站首页>App Config configuration file error
App Config configuration file error
2022-06-10 01:02:00 【Brother Chang says programming】
Preface
Beginners do upper computer development , In the process of connecting to the database , If you use The configuration file App.config To get the connection string , There are likely to be some problems , Let's summarize these problems today , And give solutions .
error message 1
“ The object reference is not set to an instance of the object ”.
《C# Program 》 Error prompt for :

【 Problem analysis 】: open App.config file , Check name Whether the string in the node is the same as that in the current brackets , Compared with , Dissimilarity , One more. S, please remember ,C# Read the name in brackets used by the node , And configuration file node configuration name It has to be consistent !

Solution
【 Problem solving 】 hold s Get rid of , Can run .
【 Other situations 】1: Some friends don't pay attention , In the string , Add any space , It can also lead to this problem , For example, below :

The blank space must be removed , In the configuration file , You can't just add any spaces .
【 Other situations 】2: If you write the node position wrong, the above error will also appear , For example, the screenshot below , The node should be written to the arrow position .

【 Other situations 】3: If App.config Configuration file not added , perhaps App.config The file didn't go to , The project can be started under the project directory , There will also be the above mistakes . For example, the following is wrong :

The following green part is the startable item of the project ,App.config The file must be put here .
【 Other situations 】4: Changed the name of the configuration file , Configuration file requirements must be default App.config Talent , If you change the file name , There are also mistakes , For example, the following is not allowed :

error message 2
“ThreeLayer.DAL.SQLHelper” The type initializer for threw an exception .
《C# Program 》 Error prompt for :

【 Problem analysis 】 Just a hint “SQLHelper The type initializer of threw an exception ”. It's usually a configuration file problem , Because we use App.config The configuration file saves the data connection string . For beginners , Because I can't understand this mistake , So I don't know where to start , Here, please remember the following troubleshooting methods .
Solution
【 resolvent 1】 The configuration file node is incorrectly written :

Originally, the node name of this place is, that is, one is missing from the above s, Change to the following :
【 resolvent 2】 The configuration file App.config If the file name is changed 、 Didn't put it in “ Can start the project ” root directory , yes , we have VS The above error will also appear in the version .( This and error 1 The solution is the same )
summary
According to the above method, we can solve the problem perfectly App.config Frequently asked questions about how to get the connection string . I hope today's content can help you .
边栏推荐
猜你喜欢

Hcip first job

Mysql——》分库分表

Sword finger offer II 013 Sum of two dimensional submatrix

Wyn enterprise, an embedded business intelligence software, has officially entered the V5.0 era!
Binary search (half search) summary

H3C IRF configuration example

Sword finger offer II 014 Anagrams in strings

Chapter 5 intra domain lateral movement analysis and defense

datagrip的两个问题

Flutter ITMS-90338: Non-public API usage - Frameworks/webview_ flutter_ wkwebview. framework
随机推荐
[HFCTF2020]BabyUpload
ECA-Net: Efficient Channel Attention for Deep Convolutional Neural Networks
消防应急疏散指示系统在某生物制药工厂项目的应用
Blue Bridge Cup · winter vacation hundred schools' real topic league tournament (Phase V) real topic exercise of cargo placement for graduate students and university group A
浅谈Cookie 和 Session——含案例及详细注解
线性规划和对偶规划学习总结
Internal network infiltration tunnel
剑指 Offer II 015. 字符串中的所有变位词
Learning notes of zhouzhihua in machine learning
Application of DFS and BFS in binary tree
gurobi解的状态及其属性获取
mpls vpn
内网渗透隧道
PCI BAR寄存器详解(一)
Intranet penetration concise notes
Republish experiment
Mysql——》分库分表
Sélection de la fonction pour déterminer si elle est vide
OSPF第一次实验
OSPF summary