none
EntityFramework 5, CodeFirst Error: Keyword not supported: 'data source'. RRS feed

  • Question

  • I am encountering a "Keyword not supported: 'data source'." exception using EF5 in VS2012 via Code First.  I've seen several entries with this problem, but no solution that works.  I have tried using single quotes and the " escape to no avail.

    Has anyone resolved this?  If so, how?

    A lot of people, including me, would appreciate an answer.

    Here's my code:

    class Program {    static void Main(string[] args)    {       InsertDestination();    } // end static void Main(string[] args)

    private static void InsertDestination()    {       string errorMessage = String.Empty;                    try       {                   Destination destination = newDestination          {             Country = "Indonesia",             Description = "EcoTourism at its best in exquisite Bali",             Name = "Bali"          };          using (var context = newBAGADBContext())          {

    context.Destinations.Add(destination); // <== Execption thrown

                context.SaveChanges();          } // end using (var context = new BAGADBContext())           } // end try

    catch (Exception err)

    {         errorMessage = err.Message;      } // end catch (Exception err)

    finally      {          if (!String.IsNullOrEmpty(errorMessage))          {                  } // endif (!String.IsNullOrEmpty(_errorMessage))       } // end finally    } // end private static void InsertDestination()  } // end class Program// end namespace BAGASplConsole

     

    The app.config[Note: I replaced "Data Source" with "Server" and got Server was not supported]:

    <?xml version="1.0" encoding="utf-8"?><configuration>

    <configSections>

    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->

    <section name="entityFramework"

    type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,

    EntityFramework, Version=5.0.0.0, Culture=neutral,

    PublicKeyToken=b77a5c561934e089" requirePermission="false" />

    </configSections>

    <startup>

    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />

      </startup>

    <connectionStrings>

    <add name="BAGADBContext" providerName="System.Data.EntityClient"

    connectionString="Data Source=SIMBA;Initial Catalog=BAGADB;uid=BAGAApp;pwd=******" />

    </connectionStrings>

    <entityFramework>

    <defaultConnectionFactory

    type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory,

    EntityFramework">

    <parameters>

    <parameter value="v11.0" />

    </parameters>

    </defaultConnectionFactory>

    </entityFramework>

    </configuration>

     

                                     

    Saturday, October 12, 2013 11:12 PM

Answers

  • Hi. The connection string seems fine, I think you need to set the providerName to System.Data.SqlClient though.

    providerName="System.Data.SqlClient"

    Sunday, October 13, 2013 1:33 AM
  • Hello EagleRed,

    If I understand correctly, you want to use Code First to connect an existing database.

    For this, there are two ways for us to write the connection string.

    One way is that you are using, and just as what J Chase said, to change the providerName="System.Data.EntityClient" to be providerName="System.Data.SqlClient" like below:

    <connectionStrings>
    
        <add name="BAGADBContext"
    
             connectionString="Data Source=(localdb)\v11.0;Initial Catalog=Code_First.AssignStateContext;Integrated Security=True;MultipleActiveResultSets=True"
    
             providerName="System.Data.SqlClient" />
    
      </connectionStrings>
    

    The ‘providerName="System.Data.EntityClient"’ is used by DataBase First and Model First.

    And another way is to declare the connection string directly in the constructor method as below:

    using (CodeFirstConnectToExistDB db = new CodeFirstConnectToExistDB("server=(localdb)\\V11.0;Integrated Security=SSPI;database=Code_First.AssignStateContext"))
    
                {
    
                    var result = db.WorkReports.ToList();
    
                } 
    

    For this, we need to add a constructor method like below:

    public CodeFirstConnectToExistDB(string connectionstring)
    
                : base(connectionstring)
    
            {
    
            }
    

    Thanks &Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, October 14, 2013 2:51 AM
    Moderator

All replies

  • Hi. The connection string seems fine, I think you need to set the providerName to System.Data.SqlClient though.

    providerName="System.Data.SqlClient"

    Sunday, October 13, 2013 1:33 AM
  • Hello EagleRed,

    If I understand correctly, you want to use Code First to connect an existing database.

    For this, there are two ways for us to write the connection string.

    One way is that you are using, and just as what J Chase said, to change the providerName="System.Data.EntityClient" to be providerName="System.Data.SqlClient" like below:

    <connectionStrings>
    
        <add name="BAGADBContext"
    
             connectionString="Data Source=(localdb)\v11.0;Initial Catalog=Code_First.AssignStateContext;Integrated Security=True;MultipleActiveResultSets=True"
    
             providerName="System.Data.SqlClient" />
    
      </connectionStrings>
    

    The ‘providerName="System.Data.EntityClient"’ is used by DataBase First and Model First.

    And another way is to declare the connection string directly in the constructor method as below:

    using (CodeFirstConnectToExistDB db = new CodeFirstConnectToExistDB("server=(localdb)\\V11.0;Integrated Security=SSPI;database=Code_First.AssignStateContext"))
    
                {
    
                    var result = db.WorkReports.ToList();
    
                } 
    

    For this, we need to add a constructor method like below:

    public CodeFirstConnectToExistDB(string connectionstring)
    
                : base(connectionstring)
    
            {
    
            }
    

    Thanks &Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, October 14, 2013 2:51 AM
    Moderator