c# - Why couldn't I check for a null reference on a connection string? -


Maybe there is a C # noob question, so do not flame me. I was trying to do this:

  If (configuration manager select connection ["primary connection connection"]. ConnectionString! = Null) {// ...}  

but give me a system Zero Refreshment Exposure was getting. I thought because it returns a string that I can only check null and move forward. It takes me a while to find the right way to do this:

  Connection String Settings CS = Configuration Manager. Connection Strings ["PrimaryConnection String"]; If (CS! = Null) {this.Connection.ConnectionString = cs.ConnectionString; }  

So in other cases, checking for a session object for some value, I will check the null like this:

  if (session ["employee ID"] = null) {_EmployeeID = System.Convert.ToInt32 (session ["employee ID"]); }  

So I wanted to know how do you know that when you can not check for null or can not?

Your blank reference exception in the parent object (Configuration Manager Connection Connection ["Primary Connection String"]) . Once you check it too, then you are fine.

Try it out:

  If ((Configuration Manager. Connection Connection ["Primary Connection" string "]! = Null) & amp; ConfigManager.ConnectionStrings [" PrimaryConnectionString "]. ConnectionString! = Null)) {etc etc}  

Note that if you use more than this method, then detection of these checks will be useful. / P>


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -