Multiple connection strings?

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
detaybey
Posts: 9
Joined: Thu 09 Jun 2011 16:23

Multiple connection strings?

Post by detaybey » Tue 12 Jul 2011 00:16

I have a web project with same code base but different contents. I used to have a configuration manager that parses the domain name, and initiates the respective connection string + site configuration into the context.

Now I'm using devart on my project but I could not find a way to initiate the Devart Entities context using it's default constructor.

When I design my classes, the Designer.cs file has this:

Code: Select all

public DataEntities() : 
                base(@"name=@Entity.DataModel1ConnectionString", "DataEntities")
        {

            this.ContextOptions.LazyLoadingEnabled = true;
        }

        /// 
        /// Initializes a new DataEntities object using the connection string found in the 'DataEntities' section of the application configuration file.
        /// 
        public DataEntities(string connectionString) : 
                base(connectionString, "DataEntities")
        {
            this.ContextOptions.LazyLoadingEnabled = true;
        }

        /// 
        /// Initialize a new DataEntities object.
        /// 
        public DataEntities(EntityConnection connection) : base(connection, "DataEntities")
        {

            this.ContextOptions.LazyLoadingEnabled = true;
        }
        
when I want to create different contexts using the second constructor(using connectionstring) it gives me error saying that my connection string is not valid (which is valid) , and If I could connect, I'm not sure how to override the second parameter (defaultContainerName).

Is there a way to get more than one connection/context using devart and override this code that was generated?

Any clues?

detaybey
Posts: 9
Joined: Thu 09 Jun 2011 16:23

Post by detaybey » Tue 12 Jul 2011 00:23

By the way as the generated code was partial, I was able to add another constructor for myself. I'm trying out this:

Code: Select all

 public partial class DataEntities
    {
       public DataEntities(string connectionString, string defaultContainerName) :
            base(connectionString, defaultContainerName)
        {
            this.ContextOptions.LazyLoadingEnabled = true;
        }
    }
and trying to create a custom context for initiated domain using:

Code: Select all

 db = new DataEntities("Server=localhost;Port=5432;User Id=xyxyxy;Password=pwpwpwpw;Database=dbdbdbdb;ConnectionLifeTime=5;", "domain1Context");

hoping to access the entities via this object. but it gives me this error:

System.ArgumentException: Keyword not supported: 'server'.

I think it converts the connectionstring to lowercase or something... I'm not sure but this connectionstring looks valid to me.

Any ideas?

detaybey
Posts: 9
Joined: Thu 09 Jun 2011 16:23

Post by detaybey » Tue 12 Jul 2011 00:37

Ok I believe the first parameter of the constructor is for the name of the key value of the connection string in the web.config. (I used to pass the full connection string value instead of the name which failed obviously)

Now I have another problem, (which I mentioned previously)

Code: Select all

[color=red]Line 11:     public partial class DataEntities
Line 12:     {
Line 13:        public DataEntities(string connectionString, string defaultContainerName) :
Line 14:             base(connectionString, defaultContainerName)
Line 15:         {[/color]
Gives the error:

@Entity.DataModel1.csdl(3,4) : error 0019: The EntityContainer name must be unique. An EntityContainer with the name 'DataEntities' is already defined.

but I'm already calling the constructor with another EntitiyContainer name like this ;

Code: Select all

 db = new DataEntities(@"name=@Entity.Domain2ConnectionString", "domain2Context");
Do I really have to create a datamodel for every database and domain? If so how would I be able to use the same codebase for multiple domains using devart?

:(

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Tue 12 Jul 2011 10:07

Take a look at the example in the ObjectContext constructor article.
More details concerning Entity Framework connections can be found in this MSDN article, for example.

Post Reply