mohammedali1989
12-16-2006, 09:37 PM
salam sir,
how can remove this errors?Login failed for user 'NULL':Not associated with a trusted SQL Server connection,
at System.Data.SqlClient.ConnectionPool.GetConnection(Boolean&isInTransation)
at System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString
option, Boolean&isInTransaction)
at System.Data.SqlClient.SqlConnection.Open()
at Enquery.Form1.button1_Click(Object sender, EnventArgs e)in c:\enquery\form1.cs:line 230
my sql server database connect using windows authentication.
this is my connection coding:-
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Xml;
namespace onlinejob1
{
/// <summary>
/// Summary description for login.
/// </summary>
public class login : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Button Button1;
SqlConnection myConnection;
SqlDataReader dr;
SqlDataAdapter sda;
protected System.Web.UI.WebControls.Label Label7;
SqlCommand cmd;
private void Page_Load(object sender, System.EventArgs e)
{
myConnection = new SqlConnection("Server=(local); uid=sa; pwd=sa; database= Online jobs;");
// Put user code to initialize the page here
this.Label7.Visible = false;
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
try
{
HttpCookie c1 = new HttpCookie("person");
string s;
DateTime dt = DateTime.Now;
TimeSpan ts = new TimeSpan(0,0,2,0);
s = Request.Form.Get("TextBox1");
//s1 = Request.Form.Get("TextBox2");
c1.Values.Add("mypass",s);
//c1.Values.Add("pwd",s1);
c1.Expires = dt.Add(ts);
Response.Cookies.Add(c1);
string id=this.TextBox1.Text;
myConnection.Open();
// string selectcmd ="select Password from Login1 where User_ID='"+id+"'";
string selectcmd ="select password from Personalinfo where userid='"+this.TextBox1.Text.ToString()+"'";
SqlCommand sqlcom = new SqlCommand(selectcmd,myConnection);
//sda = new SqlDataAdapter(sCommand1,con);
SqlDataReader dr = sqlcom.ExecuteReader();
//SqlDataReader dr = sqlcom.ExecuteReader();
string mypass=this.TextBox2.Text.ToString();
string mypass1="";
while(dr.Read())
{
//myid=dr.GetString(0);
mypass1=dr.GetString(0);
}
if(mypass == mypass1)
{
Response.Redirect("http://localhost/onlinejob1/main_frame.aspx");
}
else
{
this.Label7.Visible = true;
}
myConnection.Close();
}
catch(SqlException ex)
{
Response.Write(ex.Message);
}
}
}
}
i have install visual studio 2003 .net.
how can remove this errors?Login failed for user 'NULL':Not associated with a trusted SQL Server connection,
at System.Data.SqlClient.ConnectionPool.GetConnection(Boolean&isInTransation)
at System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString
option, Boolean&isInTransaction)
at System.Data.SqlClient.SqlConnection.Open()
at Enquery.Form1.button1_Click(Object sender, EnventArgs e)in c:\enquery\form1.cs:line 230
my sql server database connect using windows authentication.
this is my connection coding:-
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Xml;
namespace onlinejob1
{
/// <summary>
/// Summary description for login.
/// </summary>
public class login : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Button Button1;
SqlConnection myConnection;
SqlDataReader dr;
SqlDataAdapter sda;
protected System.Web.UI.WebControls.Label Label7;
SqlCommand cmd;
private void Page_Load(object sender, System.EventArgs e)
{
myConnection = new SqlConnection("Server=(local); uid=sa; pwd=sa; database= Online jobs;");
// Put user code to initialize the page here
this.Label7.Visible = false;
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
try
{
HttpCookie c1 = new HttpCookie("person");
string s;
DateTime dt = DateTime.Now;
TimeSpan ts = new TimeSpan(0,0,2,0);
s = Request.Form.Get("TextBox1");
//s1 = Request.Form.Get("TextBox2");
c1.Values.Add("mypass",s);
//c1.Values.Add("pwd",s1);
c1.Expires = dt.Add(ts);
Response.Cookies.Add(c1);
string id=this.TextBox1.Text;
myConnection.Open();
// string selectcmd ="select Password from Login1 where User_ID='"+id+"'";
string selectcmd ="select password from Personalinfo where userid='"+this.TextBox1.Text.ToString()+"'";
SqlCommand sqlcom = new SqlCommand(selectcmd,myConnection);
//sda = new SqlDataAdapter(sCommand1,con);
SqlDataReader dr = sqlcom.ExecuteReader();
//SqlDataReader dr = sqlcom.ExecuteReader();
string mypass=this.TextBox2.Text.ToString();
string mypass1="";
while(dr.Read())
{
//myid=dr.GetString(0);
mypass1=dr.GetString(0);
}
if(mypass == mypass1)
{
Response.Redirect("http://localhost/onlinejob1/main_frame.aspx");
}
else
{
this.Label7.Visible = true;
}
myConnection.Close();
}
catch(SqlException ex)
{
Response.Write(ex.Message);
}
}
}
}
i have install visual studio 2003 .net.