raholsn
raholsn

Reputation: 668

WebSecurity.InitializeDatabaseConnection and ServiceConfiguration, Azure

I have problems making

WebSecurity.InitializeDatabaseConnection(string connectionStringName, string userTableName, string userIdColumn, string userNameColumn, bool autoCreateTables)

to be configured with ServiceConfiguration.[env] in windows azure.

The problem is that WebSecurity.InitializeDatabaseConnection takes string connectionStringName and when im passing in my connectionStringName for the InitializeDatabaseConnection method it only looks in web.config for the corresponding value.

I know how to get the connectionstring from connectionStringName, I can use

  var connectionString =  CloudConfigurationManager.GetSetting("connectionStringName");

But still, InitializeDatabaseConnection need argument connectionStringName and not connectionString and therefore i need it to look in ServiceConfiguration to lookup the corresponding value for the given argument(connectionStringName).

So my question is: Is it possible to use ServiceConfiguration.[env].cscfg for WebSecurity.InitializeDatabaseConnection and let it lookup value in ServiceConfiguration from a given name? And if so , how to make it work?

Upvotes: 2

Views: 333

Answers (1)

Thomas Mueller
Thomas Mueller

Reputation: 4229

You need to use the other overload of InitializeDatabaseConnection and pass it a provider name:

public static void InitializeDatabaseConnection(
            string connectionString, 
            string providerName, 
            string userTableName, 
            string userIdColumn, 
            string userNameColumn, 
            bool autoCreateTables)

For example:

WebSecurity.InitializeDatabaseConnection(RoleEnvironment.GetConfigurationSettingValue("connectionStringName"), "System.Data.SqlClient", "UserProfile", "UserId", "UserName", true);

Upvotes: 2

Related Questions