I'm having an issue with a piece of code that has been continuously perplexing me and I'm finally breaking down and asking for a bit of help. I am trying to create an ASP.NET application with C# as the code behind language. (Please keep in mind that I am fairly new to ASP.NET and somewhat new to C#.) I am trying to code the Authentication event for the Login control and am getting hung up. In my code below, I am using bits of sample code found various places on the web and tweaked it for my application. Where I am getting hung up is the
object obj = m_Command.ExecuteScalar();
line. Whenever I run the code, it gets to this point and fails. I have added the Message Boxes purely for debugging purposes but cannot figure out why that line is failing.
I am running this on Windows 7 x64, Microsoft SQL Server 2008 R2, Visual Studio 2010.
Any helpful thoughts would be greatly appreciated.
Here is the code:
private bool DBValidate(string uName, string pWord)
{
MessageBox.Show("Hello");
//bool bflag = false;
string connString = System.Configuration.ConfigurationManager.ConnectionStrings["Connection"].ConnectionString;
MessageBox.Show("Connection String: " + connString);
//"Server=(local)\\Development;Database=InventoryTracker;Uid=sa;Pwd=trinity;";
string strSQL = "SELECT COUNT(*) FROM tblUsers WHERE (tblUsers.username = '" + uName + "') AND (tblUsers.password = " + pWord + ")";
MessageBox.Show(strSQL);
SqlConnection m_conn = new SqlConnection(connString);
SqlCommand m_Command = new SqlCommand(strSQL);
try
{
//m_Command.CommandType = System.Data.CommandType.Text;
m_conn.Open();
//m_Command.CommandType = CommandType.Text;
MessageBox.Show("String");
object obj = m_Command.ExecuteScalar();
MessageBox.Show("obj =" + obj);
if (obj.Equals('0'))
return false;
else
return true;
}
catch (Exception ex)
{
return false;
}
}
My complete web.config looks like this:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="Connection" connectionString="Data Source=localhost\DEVELOPMENT;Initial Catalog=InventoryTracker;User ID=sa;Password=trinity"/>
</connectionStrings>
<system.web>
<authentication mode="Forms">
<forms loginUrl="login.aspx"/>
</authentication>
<authorization>
<allow users="*"/>
<deny users="?"/>
</authorization>
<compilation debug="true">
<assemblies>
<add assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.ServiceModel.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Data.Services.Client, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Services.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.DynamicData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
</system.web>
<system.webServer>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
It only looks long and complicated and I'm really hoping it's something easy I may have overlooked.

New Topic/Question
Reply




MultiQuote





|