locked
System.ArgumentException: Keyword not supported: 'data source'. RRS feed

  • Question

  • Hi , 

    i have developed some table using EF 6 code first but im getting error as : 

    System.ArgumentException: Keyword not supported: 'data source'.

    Following is my connection string as i want to save data in my server :

     <connectionStrings>
        <!--<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=MarketContainer;Integrated Security=SSPI" providerName="System.Data.SqlClient" />-->
        <add name="ModelContainer" providerName="System.Data.EntityClient" connectionString="Data Source=SHAN\SHAN;Initial Catalog=SocialMarket;Persist Security Info=True;User ID=sa;Password=123;MultipleActiveResultSet=True;" />
          </connectionStrings>
     public class MarketContext : DbContext
        {
            public MarketContext(): base("ModelContainer"){ }
            public DbSet<Campaign> Campaigns {get;set;}
            public DbSet<CampaignType> CampaignTypes { get; set; }
           protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                base.OnModelCreating(modelBuilder);
                modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
    
                //Primary keys
                modelBuilder.Entity<Campaign>().HasKey(t => t.ID);
                modelBuilder.Entity<CampaignType>().HasKey(t => t.ID);
                //Primery key Db generated
                modelBuilder.Entity<Campaign>().Property(t => t.ID).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
                modelBuilder.Entity<CampaignType>().Property(t => t.ID).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
    
                //zero to many
                modelBuilder.Entity<CampaignType>().HasMany(t => t.Campaigns).WithOptional(a => a.Type).HasForeignKey(a => a.TypeID);
                }
      public class MarketInitializer : System.Data.Entity.DropCreateDatabaseIfModelChanges<MarketContext>
        {
            protected override void Seed(MarketContext context)
            {
                var cam = new List<CampaignType>{
                    new CampaignType{Enabled=true,Name="Test 1"}
                };
                cam.ForEach(s => context.CampaignTypes.Add(s));
                context.SaveChanges();
            }
        }

    Thank You , Shan Ali Khan


    • Edited by Shan Khan Sunday, March 9, 2014 10:23 PM
    Sunday, March 9, 2014 9:23 PM

Answers

  • Hello Shan Khan,

    The EntityClient provider uses storage-specific ADO.NET Data Provider classes and mapping metadata for interacting with entity data models. It is used for database or model first model.

    For Code First, we still need to use System.Data.SqlClient.

    So have a try to change your connection string as:

    <add name="ModelContainer" providerName="System.Data. SqlClient" connectionString="Data Source=SHAN\SHAN;Initial Catalog=SocialMarket;Persist Security Info=True;User ID=sa;Password=123;MultipleActiveResultSet=True;" />

    If this does not work for you, please let me know.

    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.

    • Marked as answer by Shan Khan Monday, March 10, 2014 6:22 PM
    Monday, March 10, 2014 1:46 AM

All replies

  • Hello Shan Khan,

    The EntityClient provider uses storage-specific ADO.NET Data Provider classes and mapping metadata for interacting with entity data models. It is used for database or model first model.

    For Code First, we still need to use System.Data.SqlClient.

    So have a try to change your connection string as:

    <add name="ModelContainer" providerName="System.Data. SqlClient" connectionString="Data Source=SHAN\SHAN;Initial Catalog=SocialMarket;Persist Security Info=True;User ID=sa;Password=123;MultipleActiveResultSet=True;" />

    If this does not work for you, please let me know.

    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.

    • Marked as answer by Shan Khan Monday, March 10, 2014 6:22 PM
    Monday, March 10, 2014 1:46 AM
  • I know this is an old post but I got the same error recently so for what it's worth, here's a bit of extra info and another solution:

    This is usually a connection string error, please check the format of your connection string, you can look up 'entity framework connectionstring'. However, in my case my connection string was fine and the error was caused by something completely different so I hope this helps someone:

    1. First I had an EDMX error: there was a new database table in the EDMX and the table did not exist on my database. Funny thing is the error the error was not very obvious because it was not shown in my EDMX, instead it was tucked away in visual studio in the 'Error List' window under the 'Warnings'. After I sorted it by adding the missing table to my database I still got a 'datasource' error. I was actually busy trying to add a stored procedure so see below how i resolved it:
    2. Stored procedure error: I was trying to add a stored procedure and everytime I added it via the EDMX design window I got a 'datasource' error. The solution was to add the stored procedure as blank (I deleted the contents of the stored proc and replaced it with 'select 1' and retried adding it to the EDMX). It worked! Presumably EF didn't like something inside my proc. Once I'd added the proc to EF I was then able to update the contents of the proc on my database to what I wanted it to be and it works, 'datasource' error resolved.

    weirdness

    Monday, December 22, 2014 7:23 AM