【发布时间】:2015-06-22 14:58:19
【问题描述】:
我正在尝试读取/写入 Azure 数据库,但在下面的代码中使用 SqlDataReader 时收到以下错误消息:
Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.
我可以连接到 SQL Server Management Studio 中的数据库。关于为什么会这样以及如何解决这个问题的任何建议?
我的 C# 代码:
string connectionString = "Server=tcp:[xxxxx].database.windows.net,1433;Database=[xxxxx];User ID=[xxxxx]@[xxxxx];Password=[xxxxx];Trusted_Connection=False;Encrypt=True;Connection Timeout=30;";
using (SqlConnection connection = new SqlConnection(connectionString))
{
string sql = "SELECT [xxxxx], [xxxxx] FROM [xxxxx]";
using (SqlCommand cmd = new SqlCommand(sql))
{
using (SqlDataReader reader = Database.ExecuteReader(cmd))
{
if (!reader.Read())
{
throw new Exception("[xxxxx] not found.");
}
else
{
name = Database.GetStringValue(reader, "[xxxxx]", "");
}
}
}
}
【问题讨论】:
标签: c# asp.net .net azure connection-string