【发布时间】:2017-07-04 01:03:07
【问题描述】:
我正在尝试通过在 Visual Studio 2013 中创建的 ASP.NET WebForms 网站从托管在 MS Azure 上的 SQL Server 数据库读取数据。
我已将连接字符串存储在 Web.Config 中,并已在我的代码隐藏中引用它。
但是,当我尝试在本地运行 Default.aspx 时,会显示 this 错误。
这是我的 Web.Config:
<connectionStrings>
<add name="FYPConnectionString1"
connectionString="Data Source=damo.database.windows.net;Initial Catalog=Ballinora_db;
Persist Security Info=True; User ID={Username};Password={Password};" />
</connectionStrings>
我从连接字符串中删除了“MultipleActiveResultsSets=False”以查看错误是否停止,但现在显示“加密”的错误。
因此错误出现在连接字符串的密码部分之后的下一项。 密码是否与问题有关?
此外,此用户名和密码是必需的,它们是显示在 Azure 门户中的服务器管理员登录详细信息吗?
这里也是代码隐藏:
private void bindRepeater()
{
string constr = ConfigurationManager.ConnectionStrings["FYPConnectionString1"].ConnectionString;
//-- assuming Azure connection string stored in ConnectionString config in Web.Config as YourConnString
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT Name FROM Users", con))
{
cmd.CommandType = CommandType.Text;
con.Open();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
repTest.DataSource = dt;
repTest.DataBind();
con.Close();
}
}
}
protected void btnDisplay_Click(object sender, EventArgs e)
{
this.bindRepeater();
}
【问题讨论】:
-
您好,我也使用带有 SQL 数据库的 Azure 云服务器。我更新了我的答案。请参阅此问题帖子右侧的“相关”。你身边也有类似的案例。这里也是链接。 1)stackoverflow.com/questions/1404268/… 2)stackoverflow.com/questions/9236554/…
标签: c# sql asp.net azure connection-string