4

I'm trying to connect my MVC3 project with a database in Postgres 9.1, I've follow this links: info1, info2, info3 and for the look of it, I only need the string connection in order to create a Controller.

I have the reference to the Mono.Security and Npgsql .dll, I add them to the Assembly

I'm using this connectionString:

<connectionStrings>
    <add name="TestPostgreSQLContext"         
         connectionString="metadata=res://*/Models.TestPostgreSQL.csdl|res://*/Models.TestPostgreSQL.ssdl|res://*/Models.TestPostgreSQL.msl;provider=Npgsql.NpgsqlConnection;provider connection string=&quot;data source=localhost;initial catalog=testPostgres;persist security info=True;user id=postgres;password=123456;multipleactiveresultsets=True;App=EntityFramework&quot;" 
         providerName="Npgsql.NpgsqlConnection"/>
</connectionStrings>

Code markup:

public TestPostgreSQLContext() : base("name=TestPostgreSQLContext", "TestPostgreSQLContext")
{            
    this.ContextOptions.LazyLoadingEnabled = true;
    OnContextCreated();
}
public TestPostgreSQLContext(string connectionString) : base(connectionString, "TestPostgreSQLContext")
{
    this.ContextOptions.LazyLoadingEnabled = true;
    OnContextCreated();
}
public TestPostgreSQLContext(EntityConnection connection) : base(connection, "TestPostgreSQLContext")
{
    this.ContextOptions.LazyLoadingEnabled = true;
    OnContextCreated();
}

Here's an more graphical idea: enter image description here

1 Answer 1

2

Did you declare Npgsql as a registered provider, in your app's config file or inside machine.config? (see this official Npgsql documentation

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

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.