0

I have proyect that use linq to postgresql, I have the library and Its three dependencies.

But when I try to connect to de DB I get this error:

First chance of Exception of type ' System.NullReferenceException ' in linq2db.dll. Additional information: Object reference not set to an instance of an object. (Translated).

Stack trace:

in LinqToDB.Data.DataConnection..ctor(String configurationString) in i:\linq2db\Source\Data\DataConnection.cs:line 41 in LinqToDB.Data.DataConnection..ctor() in i:\linq2db\Source\Data\DataConnection.cs:line 24 in modelo.BDGestion.bdgestionDB..ctor() in d:\Proyectos\Proyectos VisualStudio\TimeSheets\TimeSheets\modelo\BDGestion.PostgreSQL.generated.cs:línea 44 en TimeSheets.SeleccionPersonal..ctor() in d:\Proyectos\Proyectos VisualStudio\TimeSheets\TimeSheets\SeleccionPersonal.cs:line 23

public partial class SeleccionPersonal : Form
    {
        public SeleccionPersonal()
        {
            InitializeComponent();
            try
            {
                using (var db = new bdgestionDB())
                {

                }
            }catch(Exception ex){
                MessageBox.Show(ex.ToString());
            }
        }
    }

I generated the classes using the template, the connection String is well formed and properly added to de connectionStrings. Checked it by me in this solution and by a friend in other computer by its own. If you need any information just ask.

Generated class:

public partial class bdgestionDB : LinqToDB.Data.DataConnection
{
    tables...

    public bdgestionDB()
    {
        InitDataContext();
    }

    public bdgestionDB(string configuration)
        : base(configuration)
    {
        InitDataContext();
    }

    partial void InitDataContext();
}

The App.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <connectionStrings>
    <add name="Postgres" connectionString="Server=thot-test;Port=5432;Database=bdgestion;UserId=test;Password=T15Pmc;Pooling=true;MinPoolSize=10;MaxPoolSize=100;Protocol=3;"/>
  </connectionStrings>
</configuration>
  • 1
    possible duplicate of [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – MakePeaceGreatAgain Apr 21 '15 at 06:41
  • The problem it's not the NulReferenceException, i don't use an object by my self! Please, read the code before say that it's duplicated. – Oscar Vicente Perez Apr 21 '15 at 06:48
  • The exception indicates that your connectionString is incorrect and this leads to a Null reference. – Marco Apr 21 '15 at 06:50
  • What is configuration? – MakePeaceGreatAgain Apr 21 '15 at 06:51
  • The connectionString is: Server=thot-test;Port=5432;Database=bdgestion;UserId=test;Password=test;Pooling=true;MinPoolSize=10;MaxPoolSize=100;Protocol=3; and works when i use it with Npgsql directly, my friend uses a different one and same problem – Oscar Vicente Perez Apr 21 '15 at 06:52

1 Answers1

1

I googled the source snipped and got pointed in the direction of this file.

Looking at the line 41, it tries to access MappingSchema from DataProvider. From this it looks like the DataProvider is null. Googling some more I found this page. Looks like you're missing provider name in your connection string:

<add name="Northwind" 
connectionString = "Server=.\;Database=Northwind;Trusted_Connection=True;Enlist=False;" 
providerName     = "PostgreSQL" />

Here you can find an example of using Linq2db, connecting to the PostgreSQL database.