sUsername.Trim();
sPassword.Trim();
string ConnectionString = WebConfigurationManager.ConnectionStrings["dbnameConnectionString"].ConnectionString;
SqlConnection myConnection = new SqlConnection(ConnectionString);
Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Any ideas? I don't understand the error.
Well, you haven't shown which line it occurs on. It suggests that one of these occurred:
sUsername
was nullsPassword
was nullWebConfigurationManager.ConnectionStrings["dbnameConnectionString"]
returned nullBtw, calling Trim()
as a statement on its own like that is pointless. Strings are immutable - Trim()
returns the trimmed version. You want something like:
sUsername = sUsername.Trim();
sPassword = sPassword.Trim();
... but only after checking whether they're null or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With