Click to See Complete Forum and Search --> : ASP.NET connectivity from COM+


Zenzii
09-13-2006, 12:08 PM
Hiya all,

I'm doing a project where the Web application of ASP.Net should refer to a COM+ program to retrieve and validate or insert data from/to SQL server.

The problem is - that it is not retrieving and validating the data even though I have added the COM+ program.

Just to explain what I'm saying, here's the code snippet:

public class Login
{
SqlConnection con;
SqlCommand cmd;
SqlDataReader dr;
SqlTransaction sqltrans;

public string selectAdmin(string cusername, string cpassword)
{
try
{
con= new SqlConnection("server=localhost;user=sa;password=;database=Projec t");
con.Open();
sqltrans = con.BeginTransaction();
cmd = new SqlCommand("SELECT cpassword FROM administrator WHERE cusername= "+cusername+"", con);
cmd.Transaction=sqltrans;

dr=cmd.ExecuteReader();

dr.Read();

if (dr.Read()==false)
{
MessageBox.Show("'"+cusername+"' not found");
}
else
{
if( dr.GetString(0) != cpassword.Trim())
{
MessageBox.Show("Password incorrect for '" + cusername + "'.");

}
}

dr.Close();
con.Close();

}
catch(Exception)
{
return "Exception Occurred";
}

return "OK!";

}

And here's the ASP program which should validate the data and redirect it to another page:

private void Button1_Click(object sender, System.EventArgs e)
{
string status="";

string username=(user_textbox.Text).Trim();
string password=(pass_textbox.Text).Trim();

string str;
Project.Login obj = new Project.Login();
str = obj.selectAdmin(user_textbox.Text, pass_textbox.Text);
lblmessage.Text=str;

if (status=="OK!")
{
Response.Redirect("AdminPage.aspx");

}
else
{
lblmessage.Text=status;
}

}

private void cancel_button_Click(object sender, System.EventArgs e)
{
Response.Redirect("Home.aspx");
}

}

Where am I going wrong? It does not do anything whether I enter the correct or wrong username/password. It clears the password textbox but doesn't validate or show any message or error.

Please help.

russell_g_1
09-13-2006, 03:03 PM
you need to post this in the .net forum.