Home > Net >  System. NullReferenceException: "the object reference not set to an instance of an object."
System. NullReferenceException: "the object reference not set to an instance of an object."

Time:09-25

C # program problem, the great god help
String strCon=ConfigurationManager. ConnectionStrings [r]. "SQLString" ConnectionString;

Below is the specific code
 

CodePudding user response:

Check whether the XML defines the connection string,
 
String conn=ConfigurationManager. ConnectionStrings [" connSql "]. The ConnectionString;


 
<? The XML version="1.0" encoding="utf-8"?>


connSql "connectionString=" Server=.; The Database=test; Uid=sa; The PWD=sasa; MultipleActiveResultSets=true "providerName=" System. The Data. SqlClient/& gt; ""
& lt;/connectionStrings>
& lt;/configuration>

CodePudding user response:

String conn=ConfigurationManager. ConnectionStrings [" connSql "]. The ConnectionString;

<? The XML version="1.0" encoding="utf-8"?>


connSql "connectionString=" Server=.; The Database=test; Uid=sa; The PWD=sasa; MultipleActiveResultSets=true "providerName=" System. The Data. SqlClient/& gt; ""

CodePudding user response:

I am a rookie a, can you explain it

CodePudding user response:

Means you can put the configuration file & lt; Configuration> The content of the node to

CodePudding user response:

The web. Config or app. Look at the SQLString config

CodePudding user response:

 & lt; ? The XML version="1.0" encoding="utf-8"?> 



CodePudding user response:

refer to 6th floor weixin_45991012 response:
 & lt; ? The XML version="1.0" encoding="utf-8"?> 





According to the second floor is up to you, the code is called SQLString reading in XML, XML obviously didn't write you,

CodePudding user response:

Ask bosses help children
 & lt; ? The XML version="1.0" encoding="utf-8"?> 



CodePudding user response:

Post back
Then, the Database=test; Uid=sa; The PWD=sasa; Respectively the database name, user and password; System. The Data. SqlClient said connection is essentially

 
<? The XML version="1.0" encoding="utf-8"?>









The
refer to the original poster weixin_45991012 response:

CodePudding user response:

reference weixin_45991012 reply: 3/f
I am a rookie, can you explain it
first of all to practice basic skills, first, you should go to see some of the XML document to read and write code, second, you don't do error capture, three, can't read the code, if not the, good basic skill will be very painful,

CodePudding user response:

String strCon=ConfigurationManager. ConnectionStrings [r]. "SQLString" ConnectionString; This is to find the configuration file of the database connection string, but it not in your configuration file name="SQLString" configuration, he could not find, so write to find out this configuration in the configuration file is ready

CodePudding user response:

Objects have no instantiation
  •  Tags:  
  • C#
  • Related