8

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();
}
user7554035
  • 389
  • 2
  • 5
  • 19
  • Hello, I also use Azure Cloud Server with SQL Database. I updated my answer. And please refer to the 'Related' in the right of this question post. There're some similar cases with you. Here're also the links. 1) http://stackoverflow.com/questions/1404268/keyword-not-supported-data-source?rq=1 2) http://stackoverflow.com/questions/9236554/keyword-not-supported-name?rq=1 – Kay Lee Feb 16 '17 at 01:05
  • 3) http://stackoverflow.com/questions/41647501/connectionstring-keyword-not-supported?rq=1 4) http://stackoverflow.com/questions/33599853/the-connection-does-not-support-multipleactiveresultsets-despite-being-in-connec?rq=1 5) http://stackoverflow.com/questions/41483766/databinding-keyword-not-supported-metadata?rq=1 – Kay Lee Feb 16 '17 at 01:10

6 Answers6

11

You mistyped "MultipleActiveResultsSets". The "Result" in it is not plural.

Correct way: "MultipleActiveResultSets".

KOB
  • 1,156
  • 1
  • 16
  • 33
4

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.

enter image description here

IronSean
  • 1,520
  • 17
  • 31
0

The default value of MultipleActiveRe‌​‌​sultSets is False.

And if you don't need the function, just get out (delete) ' MultipleActiveRe‌​‌​sultSets=False ' of connectionstring.

Because the default value is false. If you want false, you don't need to write it by intention.

We need the function of MultipleActiveRe‌​‌​sultSets as we open second SQL connection inside while loop of SqlDataReader of the first SQL connection.

However, why ' MultipleActiveRe‌​‌​sultSets=False ' is recognized as wrong syntax is still question.

Update-

That's why I was curious why it was wrong. I think the syntax for MultipleActiveRe‌​‌​sultSets and Encrypt don't have problem.

Here is my connectionString in Web.Config:

<connectionStrings>
     <add name="GreenLeaf"  connectionString="Server=tcp:greentree.database.secure.windows.net,1433;Database=greentea;User ID=greenusers@greentree;Password=abc123;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;MultipleActiveResultSets=True;"/>
</connectionStrings>

The differences with yours are,

1) tcp 2) secure 3) @greentree (the Servername greentree together with ID like (greenusers@greentree) 4) without provider

'secure' is new feature that Azure automatically provide secure connection and you can find about this on internet.

Check the firewall of Server and just try to give a shot with above points.

Using the admin ID is correct but in aspect of security, you need to create additional Login and User for external users with limited roles and permissions.

Can you connect to Azure Server(Database) through Azure Portal? Visual Studio? Server Management Studio?

When you enter Server Management Studio, in the pop-up for connection, there's 'Server Name'. Input 'greentree.database.windows.net' there and try to login with your admin credentials.

Or can you connect to Azure Server without connectionString in Web.Config but in plain code?

And if possible, please update with the screencapture of exception, not the text only.

And for last, I'm sure you know very well, we're needed to encrypt the connectionString later for security.

Kay Lee
  • 922
  • 1
  • 12
  • 40
  • Hi @Kay Lee, I removed `MultipleActiveResultSets=False` from the connection string, but then the same error still appears. However, this time it is for _Encrypt_. So for some reason, this error is occuring after the Password within the Connection String. Does that give any extra information? – user7554035 Feb 15 '17 at 15:26
  • Hi, I will now update my connection string to look like yours above to see if that works. I can log into my database in SQL Server Management Studio with an SQL Server Authentication login. But when I put these same login details into my connection string I get that error – user7554035 Feb 16 '17 at 09:19
  • Ok, utilize the connectionString which is automatically generated by Visual Stuio or Server Management Studio. And take a look at similar cases. – Kay Lee Feb 16 '17 at 09:22
  • Does your password contain any symbols that might get in conflict with the connection and should be masked? Thinking about ; or " or sth like that. – Dominik G Feb 16 '17 at 17:00
0

I also had this problem. For me the password that I had created contained a semicolon and the password was leaking into the next part of the connection string.

I removed the semicolon in the password and it worked.

Eg the end of the password was "j;.&6". The error I was getting was

"- $exception {"Keyword not supported: '**.&6;**multipleactiveresultsets'."} System.ArgumentException"

raab
  • 46
  • 4
0

in my case i deleted

MultipleActiveRe‌​‌​sultSets=True

from connectionString in web.config

and its work fine.

Aladein
  • 184
  • 2
  • 13
0

In my case had the string

multiple active result sets=True

been added in addition to the correct string

MultipleActiveResultSets=True

This happened in a .NET 4.8 project while using Visual Studio 2022 when changing server from production name to localhost with the help of the Update wizardUpdate Wizard

I solved it by removing multiple active result sets=True from App.config/Web.config.

Jon
  • 1,060
  • 8
  • 15