View Full Version : how can connect sql database 2000 in asp.net web application or project?

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.

/// <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);


private void Button1_Click(object sender, System.EventArgs e)

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.Expires = dt.Add(ts);
string id=this.TextBox1.Text;

// 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="";


if(mypass == mypass1)
this.Label7.Visible = true;

catch(SqlException ex)



i have install visual studio 2003 .net.

12-26-2006, 01:01 AM
Change the connection string

myConnection = new SqlConnection("Server=(local); uid=sa; pwd=sa; database= Online jobs;");


myConnection = new SqlConnection("Data Source=local;Initial Catalog=Online jobs;User ID=sa;Password=sa;");

01-02-2007, 06:31 PM
you need to configure ur sql server for ASP.NET application. u haven't created the ASPNET user for ur sql server database try this:

1. Click on "New Login" button on toolbar in Sql Server enterprise manger
2. on the right side of Name textbox there is a button like [...] click it and select ASPNET (....) and click ok and create ASPNET user for ur db

then try to run ur application hope that wud work

u need to configure ur sql server for asp.net to access sql server db

Rashida Jabeen