I am trying to read from an SQL Server database which is hosted on MS Azure, through an ASP.NET WebForms website created in Visual Studio 2013.
I've stored the Connection String in Web.Config, and have referenced it in my Code-Behind.
However, when I try to run Default.aspx locally, this error is displayed.
Here is my 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>
I removed "MultipleActiveResultsSets=False" from the Connection String to see if the error stopped, but instead, the error now displays for "Encrypt".
So the error is appearing for the next item after the Password part of the connection string. Would the password have anything to do with the problem?
Also, this username and password which are required, are they the Server Admin Login details which appear in the Azure portal?
Here is the Code-Behind also:
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();
}
You mistyped "MultipleActiveResultsSets". The "Result" in it is not plural.
Correct way: "MultipleActiveResultSets".
Note for others finding this question: This can also happen if you forget to choose the proper Type (data provider) in the Azure configuration for the connection string. It happened for me with MySQL
selected instead of SQLAzure
. Since the keyword isn't on that provider it causes an error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With