1

I've test the db connection without Websecurity and it works. I've followed the tutorial from Brice Lambson http://brice-lambson.blogspot.com.es/2012/10/entity-framework-on-postgresql.html

But when I use

WebSecurity.InitializeDatabaseConnection("myContext", "UserProfile", "UserId", "UserName", autoCreateTables: false);

I get this exception:

System.InvalidOperationException was caught
  HResult=-2146233079
  Message=No user table found that has the name "UserProfile".
  Source=WebMatrix.WebData
  StackTrace:
       in WebMatrix.WebData.SimpleMembershipProvider.ValidateUserTable()
       in WebMatrix.WebData.WebSecurity.InitializeMembershipProvider(SimpleMembershipProvider simpleMembership, DatabaseConnectionInfo connect, String userTableName, String userIdColumn, String userNameColumn, Boolean createTables)
       in WebMatrix.WebData.WebSecurity.InitializeProviders(DatabaseConnectionInfo connect, String userTableName, String userIdColumn, String userNameColumn, Boolean autoCreateTables)
       in WebMatrix.WebData.WebSecurity.InitializeDatabaseConnection(String connectionStringName, String userTableName, String userIdColumn, String userNameColumn, Boolean autoCreateTables)
       in Glink.Filters.InitializeSimpleMembershipAttribute.SimpleMembershipInitializer..ctor() en c:\Users\...\InitializeSimpleMembershipAttribute.cs:line 46
  InnerException: Npgsql.NpgsqlException
       HResult=-2147467259
       Message=ERROR: 42601: Syntax error near «[»
       Source=Npgsql
       ErrorCode=-2147467259
       BaseMessage=Syntax error near «[»
       Code=42601
       Detail=""
       ErrorSql=SELECT [UserId] FROM [UserProfile] WHERE (UPPER([UserName]) = ((E'Z')))
       File=src\backend\parser\scan.l
       Hint=""
       Line=1002
       Position=8
       Routine=scanner_yyerror
       Severity=ERROR
       Where=""
       StackTrace:
            in Npgsql.NpgsqlState.<ProcessBackendResponses_Ver_3>d__a.MoveNext()
            in Npgsql.ForwardsOnlyDataReader.GetNextResponseObject()
            in Npgsql.ForwardsOnlyDataReader.GetNextRowDescription()
            in Npgsql.ForwardsOnlyDataReader.NextResult()
            in Npgsql.ForwardsOnlyDataReader..ctor(IEnumerable`1 dataEnumeration, CommandBehavior behavior, NpgsqlCommand command, NotificationThreadBlock threadBlock, Boolean synchOnReadError)
            in Npgsql.NpgsqlCommand.GetReader(CommandBehavior cb)
            in Npgsql.NpgsqlCommand.ExecuteScalar()
            in WebMatrix.Data.Database.QueryValue(String commandText, Object[] args)
            in WebMatrix.WebData.DatabaseWrapper.QueryValue(String commandText, Object[] parameters)
            in WebMatrix.WebData.SimpleMembershipProvider.GetUserId(IDatabase db, String userTableName, String userNameColumn, String userIdColumn, String userName)
            in WebMatrix.WebData.SimpleMembershipProvider.ValidateUserTable()
       InnerException: 

I guess that NpgSql could not be prepared to work with SimpleMerbership, but I'd like to know if any of you had tried this. Thank you!!

doublep
  • 11
  • 3

3 Answers3

2

You should try Daniel Nauck's AspSQLProvider: http://dev.nauck-it.de/projects/show/aspsqlprovider

It is a PostgreSQL implementation of the ASP.NET 2.0+ Membership, Role, Profile and Session-State Store Provider.

I hope it helps.

Francisco Junior
  • 1,986
  • 18
  • 25
1

I'd hint you to try changing "autoCreateTables: false" to "autoCreateTables: true".

wintermute
  • 433
  • 2
  • 12
1

Doesn't work with postgres because it injects brackets ([ ... ]) into throughout the embedded SQL:

https://github.com/aspnetwebstack/aspnetwebstack/blob/master/src/WebMatrix.WebData/SimpleMembershipProvider.cs

Eyeless Whim
  • 273
  • 1
  • 2
  • 11