I got a big problem this morning. My SQL Server had a HUGE bug yesterday and I had to reinstall it.
On my client side, when I try to login, and put the password also i always receive this error:
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.
Source Error:
public User GetUser(string username, string password)
{
// Get the User
dynamic queryStringLogon = ("SELECT Login, Id, Password, BugLogin, Guid FROM Users WHERE (Login LIKE '" + username + "') ");
SqlCommand theCommand = new SqlCommand(queryStringLogon);
SqlDataReader reader = GetData(theCommand);
Line 31: User user = null;
Line 32:
Line 33: if (reader.HasRows)
Line 34: {
Line 35: user = new User();
It's like nothing is coming back from my sql database... That's my connection string . I really don't know what's wrong with it .
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer"
connectionString="data source=.\SQLEXPRESS;Initial Catalog=DataUi;Integrated Security=SSPI;User Id=clientportaluser;Password=aspen1aspen1;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
I also set the clientportaluser with dataread and datawrite access.
private SqlDataReader GetData(SqlCommand command)
{
command.Connection = Connection;
//using (Connection)
//{
try
{
if (Connection.State == System.Data.ConnectionState.Closed)
{
Connection.Open();
}
SqlDataReader reader = command.ExecuteReader();
return reader;
}
catch (Exception e)
{
return null;
}
finally
{
// Connection.Close();
}
//}
}
private SqlConnection Connection
{
get
{
if (_sqlConnection == null)
{
_sqlConnection = new SqlConnection(_conString);
}
return _sqlConnection;
}
}
private string _conString;
private SqlConnection _sqlConnection;
FIXED : The error was users instance set to false .