gpt4 book ai didi

sql - 登录失败。该登录名来自不受信任的域,不能与Windows身份验证一起使用

转载 作者:行者123 更新时间:2023-12-04 01:28:09 28 4
gpt4 key购买 nike

我的网页位于安全服务器(https)上,并且试图连接SQL Server 2008数据库(这是普通服务器)。
我在页面本身而不是在web.config文件中编写connectionstring。而且我收到以下错误:

System.Data.SqlClient.SqlException: Login failed.
The login is from an untrusted domain and cannot be used with Windows authentication.


请帮忙,如何连接它,我是否必须为其提供一些Web服务。

我的代码如下:

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凭据。

如果要提供用户名和密码,请将Integrated Security设置为false

另外,请考虑将连接字符串放在web.config文件中-这样更安全且可重用。

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring(v=VS.100).aspx

如果为false,则在连接中指定用户ID和密码。设置为true时,将使用当前Windows帐户凭据进行身份验证。
可识别的值为true,false,yes,no和sspi(强烈建议使用),等同于true。
如果指定了用户ID和密码,并且Integrated Security设置为true,则将忽略用户ID和密码,并使用Integrated Security。

关于sql - 登录失败。该登录名来自不受信任的域,不能与Windows身份验证一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14170927/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com