Hi all I want to check if my opened connection is same as the connection string from config file.
I was trying something like this:
if(con.ConnectionString == ConfigurationManager.ConnectionStrings["Con1"].ConnectionString);
The first part is giving me right value and second part should give me the same string.
EDIT:
This is my entire connection string as I didn’t want to bother you with the details:
if (DateTime.Now.Subtract(lastDBcheck).TotalSeconds > 10 && con.ConnectionString==ConfigurationManager.ConnectionStrings["Con1"].ConnectionString)
Using
==to compare the values of strings is correct in C#.If your code isn’t working it’s most likely due to either:
To avoid the latter case I suggest that you check that your objects are not null before dereferencing them.