WebSecurity - InitializeDatabaseConnection()

定義
InitializeDatabaseConnection() 方法初始化 WebSecurity 資料庫。
該方法通過連接到包含用戶和會員資訊的資料庫來初始化 WebSecurity 系統。
C# 和 VB 語法
WebSecurity.InitializeDatabaseConnection(connectionString, userTableName,
userIdColumn, userNameColumn, autoCreateTables)
參數
參數 | 類型 | 描述 |
---|---|---|
connectionString | String |
您的 WebSecurity 資料庫的名稱 |
userTableName | String | 包含用戶資料資訊的資料庫 表 |
userIdColumn | String | 包含用戶 ID(主鍵)的資料庫 列 |
userNameColumn | String | 包含用戶名的資料庫 列 |
autoCreateTables | Boolean | true 指示如果用戶資料和會員表不存在則必須創建表,否則為 false。 |
返回值
無。
備註
如果使用 SQL Server Compact,connectionString 應該是 WebSecurity 資料庫的名稱(不帶 .sdf 檔擴展名)。否則它應該是在 Web 配置(web.config 檔)中的連接字串的名稱。
![]() |
即使 autoCreateTables 會強制資料庫 表 被自動創建,但是前提是 資料庫 本身必須已經存在。 |
---|
錯誤和異常
在下面的情況下,InitializeDatabaseConnection() 方法拋出一個 InvalidOperationException:
- SimpleMembership 沒有初始化(或者在網站配置中禁用)
技術數據
名稱 | 值 |
---|---|
Namespace | WebMatrix.WebData |
Assembly | WebMatrix.WebData.dll |
