narasiman rao

narasiman rao

  • NA
  • 519
  • 768.5k

user is not associated with a trusted sqlserver connection.

Oct 20 2013 10:29 AM

  Code as follows

 Global Function code as follows


 using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public class GlobalFunction
{
    public SqlConnection con = null;
    private string connectionstring = "Data Source=god;connect timeout = 120; Initial Catalog=CRMS Trusted_Connection=True";
    private SqlCommand cmd;
    private SqlDataReader dr;

    public string Error;

    public GlobalFunction()
    {
       
    }


    public void BindConn()
    {
        con = new SqlConnection();
        con.ConnectionString = connectionstring;
        con.Open();
    }

    public void InsertData(string SQL)
    {
        try
        {
            BindConn();
            cmd = new SqlCommand(SQL, con);
            cmd.ExecuteReader();

        }
        catch (Exception e1)
        {
            Error = e1.Message.ToString();
           
        }
    }

    public SqlDataReader ReadSql(string SQL)
    {
        con = new SqlConnection(connectionstring);
        con.Open();
        cmd = new SqlCommand(SQL, con);
        dr = cmd.ExecuteReader();
        return (dr);

    }


    public string CntString()
    {
        return connectionstring;
    }
}





  Loginpage code as follows;

 
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class LOGIN : System.Web.UI.Page
{

    private GlobalFunction GFun = new GlobalFunction();
    private SqlDataReader Dr;
    private string Sql;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
                try
            {
                Sql = "select * from Tb_Login";
                Dr = GFun.ReadSql(Sql);
                while (Dr.Read())
                {
                    if (txtUsername.Text.Equals(Dr[0].ToString().Trim()) && (txtPassword.Text.Equals(Dr[1].ToString().Trim())))
                    {

                        //Response.Redirect("CUSTOMER REGISTRATION.aspx");
                        lblmessage.Text = "User name and password match";
                    }

                    else
                    {
                        lblmessage.Text = "User name and password does not match";
                    }
                }

            }
            catch (Exception ex)
            {
                lblmessage.Text = ex.ToString();
                return;
            }
    }
}



 Error as follows

 Login failed for user
 the user is not associated with a trusted sql server connection.



 please help me what  is the problem in my code.

regards,
Rao.

Thanks.


Answers (1)