PostgreSQL + Npgsql连接器+ MVC和SimpleMembership不工作

时间:2013-07-24 09:57:05

标签: postgresql simplemembership npgsql

我在没有Websecurity的情况下测试了数据库连接,但它确实有效。我遵循了Brice Lambson http://brice-lambson.blogspot.com.es/2012/10/entity-framework-on-postgresql.html

的教程

但是当我使用

  

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

我得到了这个例外:

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: 

我想NpgSql无法准备使用SimpleMerbership,但我想知道你是否有人试过这个。 谢谢!!

3 个答案:

答案 0 :(得分:2)

你应该尝试Daniel Nauck的AspSQLProvider:http://dev.nauck-it.de/projects/show/aspsqlprovider

它是ASP.NET 2.0+成员,角色,配置文件和会话状态存储提供程序的PostgreSQL实现。

我希望它有所帮助。

答案 1 :(得分:1)

我暗示您尝试将“autoCreateTables:false”更改为“autoCreateTables:true”。

答案 2 :(得分:1)

不适用于postgres,因为它在整个嵌入式SQL中注入括号([...]):

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