5

I have an Asp.net MVC5 application and have published it to Microsoft Azure. I first migrated my .mdf files toSql Azure Databases. The database connection string provided in the Azure Portal is not working.

[ArgumentException: Keyword not supported: 'server'.]

My connection string is as follows web.config

connectionString="
    Server=tcp:dbprojectserver.database.windows.net,1433;
    Initial Catalog=db_project;
    Persist Security Info=False;
    User ID=username@servername;
    Password=kenth&&123;
    Encrypt=True;
    TrustServerCertificate=False;
    Connection Timeout=30;
    "

I believe so there is something wrong with this connection string. Any help regarding that is highly appreciated.

EDIT

Reading from here SQL Server Connection Strings and following EF Db first or Model first connection string example

<add name="ConnectionStringName"
    providerName="System.Data.EntityClient"
    connectionString="metadata=res://*/ ContextClass.csdl|res://*/ ContextClass.ssdl|res://*/ ContextClass.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=ServerName;Integrated Security=False;User Id=userid;Password=password;MultipleActiveResultSets=True&quot;" />

This is what I am using according to above example

<add name="ProjectEntities" connectionString="metadata=res://*/ ProjectWeb.Models.User.csdl|res://*/ ProjectWeb.Models.User.ssdl|res://*/ ProjectWeb.Models.User.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=tcp:dbprojectserver.database.windows.net,1433;Integrated Security=False;User Id=username@servername;Password=kenth$$123;MultipleActiveResultSets=True&quot;
      " providerName="System.Data.EntityClient"/>

It says

Keyword not supported 'data source'

6
  • How did you get this ConectionString? Is this one really provided by the portal? Because I looked at a few samples of my own and saw only "Data Source="...", never Server="" Commented Jan 2, 2017 at 10:33
  • @Henk, yes this is what is provided by the portal Commented Jan 2, 2017 at 10:43
  • @HenkHolterman There are a few keywords that mean the same thing. Commented Jan 2, 2017 at 11:29
  • Have you seen this one: stackoverflow.com/a/6647089/1658906 ? Commented Jan 2, 2017 at 12:32
  • @juunas, please see the edit the section of the question. Commented Jan 2, 2017 at 13:23

2 Answers 2

5

I had the same problem when specified EF connection string on the Azure Portal in Application Service settings (Application settings -> Connection strings).

To fix it:

  • Replace &quot; with "
  • Specify connection string type as Custom but not as SQL Database.

Also, as I can see you do not have Initial Catalog in your latest example. You need to add it and specify your database in this parameter.

Finally your connection string for application settings in Azure portal should look like this:

metadata=res://*/ ProjectWeb.Models.User.csdl|res://*/ ProjectWeb.Models.User.ssdl|res://*/ ProjectWeb.Models.User.msl;
provider=System.Data.SqlClient;
provider connection string="Data Source=tcp:dbprojectserver.database.windows.net,1433;Initial Catalog=<your database>;Integrated Security=False;User Id=username@servername;Password=kenth$$123;MultipleActiveResultSets=True";
Sign up to request clarification or add additional context in comments.

1 Comment

Indeed, single tick quotes instead of XML escaping works!
1

If it is an error on the code line of connection string then try remove below code from web.config file.

Trust Server Certificate=True

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.