ralmsdeveloper / EntityFrameworkCore.FirebirdSQL

FirebirdSQL database provider for Entity Framework Core.
Other
44 stars 26 forks source link

Error connecting to database on Mac #53

Closed joarb closed 4 years ago

joarb commented 4 years ago

The issue

I'm trying to connect to a database from EFCore.

Steps to reproduce

using (var dbContext = new ApplicationDBContext(@"DataSource=localhost;Port=3050;Database=blogdb;User=SYSDBA;Password=masterkey;CharSet=UTF8;"))
            {
                dbContext.Blog.Add(new Blog
                {
                    Url = "https://github.com/ralmsdeveloper/EntityFrameworkCore.FirebirdSql"
                });
                dbContext.SaveChanges();

                var blogs = dbContext.Blog;

                foreach(var entry in blogs) {
                    Console.WriteLine(entry.BlogId + ": " + entry.Url);
                }
            }

where

public class ApplicationDBContext : DbContext
    {

        public DbSet<Blog> Blog { get; set; }
        readonly string _connectionString;

        public ApplicationDBContext(string connectionString)
        {
            _connectionString = connectionString;
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseFirebird(_connectionString);
        }

        protected override void OnModelCreating(ModelBuilder model)
        {
            //Fluent Api
            model.Entity<Blog>(entity =>
            {
                entity.HasIndex(e => e.BlogId)
                    .HasName("Id")
                    .IsUnique();
            });
        }

    }

I've verified connecting to the same database using isql:

myusers-MBP:FBExample myuser$ isql localhost:blogdb -user SYSDBA -password masterkey
Database: localhost:blogdb, User: SYSDBA
SQL> quit;
myusers-MBP:FBExample myuser$ 

which should be sufficient verification.

Error details

If you are seeing an exception, include the full exceptions details (message and stack trace).

Unhandled exception. FirebirdSql.Data.FirebirdClient.FbException (0x80004005): Error occurred during login, please check server firebird.log for details
 ---> Error occurred during login, please check server firebird.log for details
   at FirebirdSql.Data.FirebirdClient.FbConnectionInternal.Connect()
   at FirebirdSql.Data.FirebirdClient.FbConnectionPoolManager.Pool.CreateNewConnection(ConnectionString connectionString)
   at FirebirdSql.Data.FirebirdClient.FbConnectionPoolManager.Pool.CreateNewConnectionIfPossibleImpl(ConnectionString connectionString)
   at FirebirdSql.Data.FirebirdClient.FbConnectionPoolManager.Pool.GetConnection(FbConnection owner)
   at FirebirdSql.Data.FirebirdClient.FbConnectionPoolManager.Get(ConnectionString connectionString, FbConnection owner)
   at FirebirdSql.Data.FirebirdClient.FbConnection.Open()
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnection(Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.BeginTransaction(IsolationLevel isolationLevel)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.BeginTransaction()
   at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(DbContext _, ValueTuple`2 parameters)
   at Microsoft.EntityFrameworkCore.Storage.Internal.NoopExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
   at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(IEnumerable`1 commandBatches, IRelationalConnection connection)
   at Microsoft.EntityFrameworkCore.Storage.RelationalDatabase.SaveChanges(IReadOnlyList`1 entries)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(IReadOnlyList`1 entriesToSave)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)
   at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)
   at Microsoft.EntityFrameworkCore.DbContext.SaveChanges()
   at FBExample.Program.Main(String[] args) in /.../FBExample/Program.cs:line 28

There is nothing related to this error in the firebird.log file.

Further technical details

Firebird version: 3.0.4. EntityFrameworkCore.FirebirdSql version: 7.1.1.

Other details about my project setup: None

ralmsdeveloper commented 4 years ago

I am very busy with some things of the company, active in the project only in early 2020, so I recommend using the following provider: https://github.com/cincuranet/FirebirdSql.Data.FirebirdClient

WiSch4711 commented 4 years ago

Hello, Joar, I had the same problem, but I could fix it tonight. The problem is the driver of the FirebirdSql version 6.0.6 or higher. Until version 6.0.5 the function UseFirebird() is in the namespace using FirebirdSql.EntityFrameworkCore.Firebird.Extensions; As of version 6.0.6, the function is available in using Microsoft.EntityFrameworkCore;

Go back to version 6.0.5 and the bug is no longer there. I had the following error message:

Translated with www.DeepL.com/Translator (free version)

2019-11-29 01:12:37.8027|ERROR|Microsoft.EntityFrameworkCore.Query|An exception occurred in the database while iterating the results of a query for context type 'WS.Data.BL.EFC.Fb25.Fb25SwebBroker01.Models.Fb25SwebBroker01Db'. System.NullReferenceException: Object reference not set to an instance of an object. at EntityFrameworkCore.FirebirdSql.Query.Sql.Internal.FbQuerySqlGenerator..ctor(QuerySqlGeneratorDependencies dependencies, SelectExpression selectExpression, IFbOptions fBOptions) at EntityFrameworkCore.FirebirdSql.Query.Sql.Internal.FbQuerySqlGeneratorFactory.CreateDefault(SelectExpression selectExpression) at Microsoft.EntityFrameworkCore.Query.Expressions.SelectExpression.CreateDefaultQuerySqlGenerator() at Microsoft.EntityFrameworkCore.Query.Internal.ShaperCommandContext.b__140(FactoryAndReader s) at Microsoft.EntityFrameworkCore.Internal.NonCapturingLazyInitializer.EnsureInitialized[TParam,TValue](TValue& target, TParam param, Func2 valueFactory) at Microsoft.EntityFrameworkCore.Query.Internal.ShaperCommandContext.NotifyReaderCreated(DbDataReader dataReader) at Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable1.AsyncEnumerator.BufferlessMoveNext(DbContext , Boolean buffer, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable1.AsyncEnumerator.MoveNext(CancellationToken cancellationToken) at System.Linq.AsyncEnumerable.FirstOrDefault_[TSource](IAsyncEnumerable1 source, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.TaskResultAsyncEnumerable1.Enumerator.MoveNext(CancellationToken cancellationToken) at System.Linq.AsyncEnumerable.SelectEnumerableAsyncIterator2.MoveNextCore(CancellationToken cancellationToken) at System.Linq.AsyncEnumerable.AsyncIterator1.MoveNext(CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.ExceptionInterceptor1.EnumeratorExceptionInterceptor.MoveNext(CancellationToken cancellationToken)

After downgrading to version 6.0.5 the data was retrieved properly from the database.

Many greetings

Winfried

joarb commented 4 years ago

Thanks for the input @ralmsdeveloper and @WiSch4711 . I wasn't able to log in using the 6.5.0-version either (I suppose 6.0.5 was a typo?), so I'll head over to https://github.com/cincuranet/FirebirdSql.Data.FirebirdClient and ask there instead.

WiSch4711 commented 4 years ago

Sorry, FirebirdSql.EntityFrameworkCore.Firebird Version 6.5.0 is correct.

Winfried

Am 01.12.2019 um 10:30 schrieb Joar Bølstad:

Thanks for the input @ralmsdeveloper https://github.com/ralmsdeveloper and @WiSch4711 https://github.com/WiSch4711 . I wasn't able to log in using the 6.5.0-version either (I suppose 6.0.5 was a typo?), so I'll head over to https://github.com/cincuranet/FirebirdSql.Data.FirebirdClient and ask there instead.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ralmsdeveloper/EntityFrameworkCore.FirebirdSQL/issues/53?email_source=notifications&email_token=AFK2RTYGDFX7VLJO4C4KAPLQWN7Z3A5CNFSM4JSTSNR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFRCZDA#issuecomment-560082060, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFK2RT7DAG6BEEHTZ5WXALLQWN7Z3ANCNFSM4JSTSNRQ.

-- Mit freundlichem Gruß aus Siegburg

Winfried Schneller winfried@schneller.de +49 2241 604051