我已经将连接字符串存储在Web.Config中,并在我的代码后台中引用它。
然而,当我尝试在本地运行Default.aspx时,会显示此错误。
以下是我的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"以查看错误是否停止,但是相反,现在显示的是"Encrypt"的错误。
因此,在连接字符串的密码部分之后,下一个项目出现了错误。密码是否与问题有关?
此外,这些需要的用户名和密码,它们是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();
}