Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how can connect sql database 2000 in asp.net web application or project?

    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.

  • #2
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Change the connection string

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

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

  • #3
    New to the CF scene
    Join Date
    Jan 2007
    Location
    Islamabad
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

    Regards,
    Rashida Jabeen
    http://www.akaas.net/dot-net-faqs.htm


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •