6

I am using Entity Framework Code First 4.3 + Azure and having difficulties connecting to the database. The error I get is the following (on the first query):

Keyword not supported: 'server'.

I have the following connection set up in my Web.config

<configSections>
    type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  </configSections>

  <connectionStrings>
    <add name="TestDBContext"
         connectionString="Server=tcp:[SUBSCR].database.windows.net,1433;Database=[MyDB];User ID=[user];Password=[pass];Trusted_Connection=False;Encrypt=True;PersistSecurityInfo=True"
         providerName="System.Data.EntityClient" />
  </connectionStrings>

My DbContext implementing class uses the connection string's name:

public class MyContext : DbContext, IMyContext
    {
        public MyContext()
            : base("TestDBContext")
        {
            Configuration.LazyLoadingEnabled = true;
            Configuration.ProxyCreationEnabled = true;
        }

Can you tell what is going on?

6 Answers 6

5

I just had the same problem.

You're missing all the metadata in the connection string that Entity Framework requires. The connection string provided by SQL Azure needs to inserted within the provider connection string parameter of EF's connection string.

<add name="MyConnectionString" connectionString="metadata=res://*/Model.Model.csdl|res://*/Model.Model.ssdl|res://*/Model.Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;[PUT SQL AZURE CONN STRING HERE]&quot;" providerName="System.Data.EntityClient" />

You'll need to use the metadata from your own project. I pulled that metadata from an EF project generating from an existing database.

Sign up to request clarification or add additional context in comments.

2 Comments

I'm using EF code first + DbContext (I'm not generating my data model from the database) so I don't have any metadata available at development time.
@Sese If you're using Code First, then your connection string provider should be System.Data.SqlClient not System.Data.EntityClient.
2

I had the same problem. I solved, putting in the web.config this connectionstring:

<add name="eManagerTurModelConnection" connectionString="metadata=res://*/ORM.eManagerFinanceModel.csdl|res://*/ORM.eManagerFinanceModel.ssdl|res://*/ORM.eManagerFinanceModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=<server>.database.windows.net;Initial Catalog=eManagerTur;Integrated Security=False;User ID=<user>;Password=<Password>;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

And after I removed the connectionstring of my website, worked, because it was not getting the connection string that I added in my web.config.

English bad... =)

Comments

2

The provider should be providerName="System.Data.SqlClient"

I connected to Azure from VS and then looked at the properties and set my connection string and provider name.

 <add name="context" connectionString="Data Source=myServer,myPort;Initial Catalog=myDBName;Persist Security Info=True;User ID=myUserName;Password=myPassword;" providerName="System.Data.SqlClient"/>

I was then able to run update-database with no issues.

Comments

0

i tried like this, it may help you. may be 1433 is making problem, is it port no ? or what? . try like this.

check this link Windows Azure with Sql

<add name="dbContext" connectionString="Server=tcp:xxxxxxxx.database.windows.net;Database=xxxxxxxx;User ID=xxxxxxx@xxxxxxxxx;Password=xxxxxxxxxx;Trusted_Connection=False;Encrypt=True;" providerName="System.Data.EntityClient" />

1 Comment

tried it, it doesn't work...1433 is the default port for sql server and I copy pasted the connection string from my Azure subscription/database.
0

Try this:

Data Source=tcp:YOUR-DATABASE-HERE.database.windows.net,1433; Database=GolfRounds; User ID=YOUR-USERNAME@YOUR-SERVER; Password=YOUR-PASSWORD; Trusted_Connection=False; Encrypt=True;

There is also an MSDN article at http://msdn.microsoft.com/en-us/library/windowsazure/ff951633.aspx that may be helpful.

1 Comment

Keyword not supported: 'data source'.
-1

I had a similar problem where I did not have access to the metadata, in this case you need to use System.Data.SqlClient as the provider. You will also need to add MultipleActiveResultSets=True to your connection string

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.