I am using visual studio 2010 and Oracle 10g. Operating system: Windows 7 home basic. If I use the following code in visual studio 2005, I am getting a correct output. But in Visual Studio 2010 I get an error
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OracleClient;
using System.Windows.Forms;
public partial class Default2 : System.Web.UI.Page
{
OracleConnection con = new OracleConnection("uid=scott;pwd=tiger;data source=");
OracleCommand cmd = new OracleCommand();
OracleDataReader dr;
string name1, pass1;
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
}
protected void Button1_Click(object sender, EventArgs e)
{
cmd = new OracleCommand("Select* from tb1 where name='" + TextBox1.Text + "'and pass='"+TextBox2.Text + "'", con);
dr = cmd.ExecuteReader();
while (dr.Read())
{
name1 = dr[0].ToString();
pass1 = dr[1].ToString();
}
if (name1 == TextBox1.Text && pass1 == TextBox2.Text)
{
Response.Redirect("Home.aspx");
}
else
{
MessageBox.Show("Incorrect user name or password");
}
}
}
It could be a problem with the
tnsnames.ora, where your connection is defined.You can omit
tnsnames.orawith this connection string: