PostgreSQL connection in Xamarin

Is there any way to connect my Xamarin app with postgreSQL databse without using WebService?
Looks like NpgSQL supports .NetStandard and so is my app, but it fails on deploy to android/iOS device.

line:
NpgsqlConnection myConnection = new NpgsqlConnection(strConnString); throws an error:

Unhandled Exception:
System.TypeInitializationException: The type initializer for 'System.Collections.Generic.List`1' threw an exception. occurred

works in .Net Core Console app without any problem.

Answers

  • RohitSingh.6601RohitSingh.6601 USMember ✭✭

    Hello In my suggestion the way of hosting database on any other platform is should be in the form of web services.As you have the web services you can call them in your xamarin project.

  • Hi,

    I try connect directly from my Xamarin.Forms App into postgreSQL database which is hosted in local network. I'm using dotnetstandard 2.0 and I've installed npgsql libraries in all projects.

    When I try to connect in Android application everything works good. But when I check connection via iOS app it returns me an error described below. Anyone meet with this?

    [0:] ***** Failed connection: System.NotImplementedException: byref delegate
    at System.Linq.Expressions.Interpreter.LightLambda.CreateCustomDelegate (System.Type delegateType) [0x001d4] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.3.0.47/src/mono/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/LightLambda.cs:359
    at System.Linq.Expressions.Interpreter.LightLambda.MakeDelegate (System.Type delegateType) [0x00012] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.3.0.47/src/mono/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/LightLambda.cs:383
    at System.Linq.Expressions.Interpreter.LightDelegateCreator.CreateDelegate (System.Runtime.CompilerServices.IStrongBox[] closure) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.3.0.47/src/mono/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/LightDelegateCreator.cs:33
    at System.Linq.Expressions.Interpreter.LightDelegateCreator.CreateDelegate () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.3.0.47/src/mono/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/LightDelegateCreator.cs:28
    at System.Linq.Expressions.Expression1[TDelegate].Compile (System.Boolean preferInterpretation) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.3.0.47/src/mono/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/LambdaExpression.cs:200 at System.Linq.Expressions.Expression1[TDelegate].Compile () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.3.0.47/src/mono/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/LambdaExpression.cs:181
    at Npgsql.TypeHandling.NpgsqlTypeHandler1[TDefault].GenerateNonGenericValidationMethod (System.Type handlerType) [0x001d2] in /home/roji/projects/npgsql/src/Npgsql/TypeHandling/NpgsqlTypeHandler.cs:281
    at Npgsql.TypeHandling.NpgsqlTypeHandler1[TDefault].<.ctor>b__4_0 (System.Type t) [0x00000] in /home/roji/projects/npgsql/src/Npgsql/TypeHandling/NpgsqlTypeHandler.cs:69
    at (wrapper delegate-invoke) System.Func2[System.Type,System.ValueTuple2[Npgsql.TypeHandling.NpgsqlTypeHandler1+NonGenericValidateAndGetLength[System.String],Npgsql.TypeHandling.NpgsqlTypeHandler+NonGenericWriteWithLength]]:invoke_TResult_T (System.Type) at System.Collections.Concurrent.ConcurrentDictionary2[TKey,TValue].GetOrAdd (TKey key, System.Func2[T,TResult] valueFactory) [0x00034] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.3.0.47/src/mono/external/corefx/src/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentDictionary.cs:1044 at Npgsql.TypeHandling.NpgsqlTypeHandler1[TDefault]..ctor () [0x00006] in /home/roji/projects/npgsql/src/Npgsql/TypeHandling/NpgsqlTypeHandler`.cs:68
    at Npgsql.TypeHandlers.TextHandler..ctor (Npgsql.NpgsqlConnection connection) [0x0000c] in /home/roji/projects/npgsql/src/Npgsql/TypeHandlers/TextHandler.cs:75
    at Npgsql.TypeHandlers.UnknownTypeHandler..ctor (Npgsql.NpgsqlConnection connection) [0x00000] in /home/roji/projects/npgsql/src/Npgsql/TypeHandlers/UnknownTypeHandler.cs:44
    at Npgsql.TypeMapping.ConnectorTypeMapper..ctor (Npgsql.NpgsqlConnector connector) [0x0004f] in /home/roji/projects/npgsql/src/Npgsql/TypeMapping/ConnectorTypeMapper.cs:86
    at Npgsql.NpgsqlConnector+d__150.MoveNext () [0x00014] in /home/roji/projects/npgsql/src/Npgsql/NpgsqlConnector.cs:463

  • According to my last issue. Connection in iOS Project works properly when downgraded to npgsql in version 3.2.6.

Sign In or Register to comment.