登录失败.登录名来自不受信任的域,不能与 Windows 身份验证一起使用 [英] Login failed. The login is from an untrusted domain and cannot be used with Windows authentication
问题描述
我的网页在安全服务器 (https) 上,我正在尝试连接 SQL Server 2008 数据库,这是普通服务器.我在页面本身上编写连接字符串,而不是在 web.config 文件中.我收到以下错误:-
My webpages are on secured server (https), and I am trying to connect the SQL Server 2008 Database, which is normal server. I am writing connectionstring on page itself, not in web.config file. And I am getting following error:-
System.Data.SqlClient.SqlException: Login failed.
The login is from an untrusted domain and cannot be used with Windows authentication.
请帮忙,我该如何连接它,我是否需要为它制作一些网络服务.
Please help, how can I connect it, does I have to make some webservices for it.
我的代码如下:
public void FillCity()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "integrated security=SSPI;data source=dev-fcb; user id=sa;password=password;"
+"persist security info=False;database=mediapro";
con.Open();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand("select * from StateCityMaster where IsActive='1' order by CityName", con);
DataSet ds = new DataSet();
da.Fill(ds);
string CityName = string.Empty;
if (ds.Tables[0].Rows.Count > 0)
{
CityName = ds.Tables[0].Rows[0]["CityName"].ToString();
}
DataSet dset = new DataSet();
da.Fill(dset);
if (dset.Tables[0].Rows.Count > 0)
{
drpCity.DataSource = dset;
drpCity.DataTextField = "CityName";
drpCity.DataValueField = "CityName";
drpCity.DataBind();
}
drpCity.Items.Insert(0, new ListItem("--Select--", "0"));
con.Close();
}
推荐答案
您的连接字符串告诉它使用集成安全 SSPI,它将使用 Windows 凭据.
Your connection string is telling it to use integrated security SSPI, which will use the Windows credentials.
如果您要提供用户名和密码,请将 Integrated Security
设置为 false
.
Set Integrated Security
to false
if you are going to be providing the username and password.
另外,考虑将您的连接字符串放在 web.config 文件中 - 它更安全且可重用.
Also, consider putting your connection string inside of the web.config file - it is more secure and reusable.
如果为 false,则在连接中指定用户 ID 和密码.如果为 true,则使用当前的 Windows 帐户凭据进行身份验证.识别值为true、false、yes、no、sspi(强烈推荐),相当于true.如果指定了用户 ID 和密码并且集成安全设置为 true,则用户 ID 和密码将被忽略并使用集成安全.
这篇关于登录失败.登录名来自不受信任的域,不能与 Windows 身份验证一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!