错误显示用户未与受信任的sql server连接关联 [英] error show the user is not associate with a trusted sql server connection

查看:122
本文介绍了错误显示用户未与受信任的sql server连接关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码如下





类文件我的代码如下



公共类GlobalFunction

{

public SqlConnection con = null;

private string connectionstring =Data Source = god; connect timeout = 120;初始目录= CRMS;

私有SqlCommand cmd;

私有SqlDataReader博士;



公共字符串错误;



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(例外e1)

{

错误= e1.Message.ToString();



}

}



public SqlDataReader ReadSql(string SQL)

{

con = new SqlConnection(connectionstring);

con.Open() ;

cmd = new SqlCommand(SQL,con);

dr = cmd.ExecuteReader();

return(dr);



}





公共字符串CntString()

{

返回连接字符串;

}

}







设计页面代码如下



private GlobalFunction GFun = new GlobalFunction();

private SqlDataReader Dr;

private string Sql;





prot已经无效Button1_Click(对象发件人,EventArgs e)

{

尝试

{

Sql =select *来自Tb_Login;

Dr = GFun.ReadSql(Sql);

while(Dr.Read())

{

if(txtUsername.Text.Equals(Dr [0] .ToString()。Trim())&&(txtPassword.Text.Equals(Dr [1] .ToString()。Trim())))

{

lblmessage.Text =用户名和密码匹配;

}



else

{

lblmessage.Text =用户名和密码不匹配;

}

}



}

catch(例外情况)

{

lblmessage .Text = ex.ToString();

返回;

}

}





当我跑并键入用户名和密码,然后单击登录按钮显示错误,如下所示





用户未与受信任的sql server连接关联





请帮帮我。



我的问题是什么代码。



问候,

narasiman P.

Code as follows


in class file my code as follows

public class GlobalFunction
{
public SqlConnection con = null;
private string connectionstring = "Data Source=god;connect timeout = 120; Initial Catalog=CRMS";
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;
}
}



Design page code as follows

private GlobalFunction GFun = new GlobalFunction();
private SqlDataReader Dr;
private string Sql;


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())))
{
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;
}
}


When i run and type the username and password and click the Login button shows error as follows


the user is not associate with a trusted sql server connection


please help me.

what is the problem in my code.

regards,
narasiman P.

推荐答案

没有在您的连接字符串中,您提到了用户名&用于连接数据库的密码。如果您有一个sql用户名&密码,在连接字符串中指定相同。该错误明确指出您无权使用Windows身份验证登录。如果您已获得使用Windows帐户登录的权限,请尝试创建如下所示的连接字符串 -



No where in your connection string you have mentioned username & password for connecting to the database. If you have an sql username & password, specify the same in the connection string. The error clearly specifies that you are not authorized to login using your windows authentication. if you have been given access to login with your windows account then try creating connection string like given below -

Server=myServerAddress;Database=myDataBase;
Trusted_Connection=yes;





否则请指定您的sql用户名&密码如下 -





Else specify your sql username & password like below -

Server=myServerAddress;Database=myDataBase;Uid=myUsername;
Pwd=myPassword;


这篇关于错误显示用户未与受信任的sql server连接关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆