WebSecurity - InitializeDatabaseConnection()
WebSecurity object
define
InitializeDatabaseConnection() The method initializes the WebSecurity database.
The method initializes by connecting to the database containing user and membership information WebSecurity system.
C# and VB syntax
WebSecurity.InitializeDatabaseConnection(
connectionString, userTableName, userIdColumn, userNameColumn, autoCreateTables
)
Parameters
| Parameters | Type | Description |
|---|---|---|
| connectionString | String |
Your WebSecurity database name |
| userTableName | String | The database containing user profile information table |
| userIdColumn | String | The database column containing the user ID (primary key) column |
| userNameColumn | String | The database column containing the username column |
| autoCreateTables | Boolean | true Indicates whether the user profile and membership tables must be created if they do not exist; otherwise false。 |
Return Value
none.
Notes
If SQL Server Compact is used,connectionString should be the name of the WebSecurity database (without the .sdf file extension). Otherwise it should be the name of the connection string in the web configuration (web.config file).
![]() |
Even if autoCreateTables forces the database table to be created automatically, the precondition is that Database itself must already exist. |
|---|
Errors and exceptions
In the following cases,InitializeDatabaseConnection() The method throws an InvalidOperationException:
- SimpleMembership Not initialized (or disabled in the website configuration)
Technical data
| Name | Value |
|---|---|
| Namespace | WebMatrix.WebData |
| Assembly | WebMatrix.WebData.dll |
WebSecurity object
