WebSecurity.InitializeDatabaseConnection - How specify a db schema?

后端 未结 4 1858
日久生厌
日久生厌 2021-01-05 23:16

I am using SimpleMembership (http://blog.osbornm.com/archive/2010/07/21/using-simplemembership-with-asp.net-webpages.aspx) but I am unable to have place my custom user table

相关标签:
4条回答
  • 2021-01-05 23:38

    I think the key is that it will use whatever the default schema is associated with your user id. In SQL Server, you might try specifying a default schema other than dbo for your user account and then I think it will create the tables in that schema, but I don't think you can specify the schema on the call to InitializeDatabaseConnection.

    0 讨论(0)
  • 2021-01-05 23:39

    Try this:

    WebSecurity.InitializeDatabaseConnection(connectionStringName: "ApplicationServices", userTableName: "MySchema].[User", userIdColumn: "ID", userNameColumn: "Username", autoCreateTables: true);
    
    0 讨论(0)
  • 2021-01-05 23:43

    I use my own schema for users.

    My table is called CORE.PROFILES, to work with websecurity I have a SQL synonym dbo.PROFILES.

    To do it run this statement in SQL Server:

    CREATE SYNONYM dbo.profiles FOR core.profiles;
    

    I hope this help you.

    0 讨论(0)
  • 2021-01-05 23:57

    Version 2.0.0.0 of the WebMatrix.WebData assembly generates its create table statement as follows.

    "CREATE TABLE " + this.SafeUserTableName + "(" + this.SafeUserIdColumn + " int NOT NULL PRIMARY KEY IDENTITY, " + this.SafeUserNameColumn + " nvarchar(56) NOT NULL UNIQUE)"
    

    SafeUserTableName has the following implementation.

    return "[" + this.UserTableName + "]";
    

    As @anderly assumed, the result will be that the table will be created in the default schema of the user in the connection string.

    By the same token, at runtime, the implementation of the SafeUserTableName method results in the entire contents of the UserTableName parameter being interpreted as a table name - in the default schema.

    SimpleMembershipProvider therefore requires the user table to be in the default schema.

    0 讨论(0)
提交回复
热议问题