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.
Loading
RobbinsonPosted Oct 21, 2013, 7:07 AM
The SQL server has been configured to operate in "Windows Authentication Mode (Windows Authentication)" and doesn't allow the use of SQL accounts.
Follow the steps listed below to configure your Sql server for mix mode.
1) Right click on your SQL Server node in Management Studio
2) choose Properties.
3) On the dialog that appears go to security tab and make sure that "SQL Server and Windows Authentication mode" is selected
4) When you are prompted to re-start the SQL Server service, click Yes.
Hope this will help you out.
Please Don't forget to mark as answer if this post helps you.