-3

whenever this line execute WebSecurity.InitializeDatabaseConnection then it is giving error "Connection string "Data Source=BBATRIDIP\SQLSERVER2008R2;Initial Catalog=test;User ID=sa,password=test#" was not found."

again LazyInitializer.EnsureInitialized return error "An exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll but was not handled in user code Additional information: Exception has been thrown by the target of an invocation."

anyone tell me where i made the mistake. my WebSecurity.InitializeDatabaseConnection() code look like WebSecurity.InitializeDatabaseConnection(@"Data Source=BBATRIDIP\SQLSERVER2008R2;Initial Catalog=test;User ID=sa,password=test#", "UserProfile", "UserId", "UserName", autoCreateTables: true);

thanks

this is how my connection string look like in web.config

  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=BBATRIDIP\SQLSERVER2008R2;Initial Catalog=test;User ID=sa,password=tintin11#" providerName="System.Data.SqlClient" />
  </connectionStrings>

but still getting error. any idea?

Thomas
  • 33,544
  • 126
  • 357
  • 626
  • 1
    Did you try **reading** the error or the documentation, and understanding it? The first string parameter of `WebSecurity.InitializeDatabaseConnection(string, ...)` accepts a connection string **name**, not an entire connection string. – CodeCaster Sep 03 '15 at 12:08

1 Answers1

0

As you can see from MSDN signature of this method is next:

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

So as first parameter you must provide connection name from app.config or web.config file, e.g. "SecurityConnectionString"

DrAlligieri
  • 211
  • 5
  • 10
  • see my edit post like how my connection string look like. – Thomas Sep 03 '15 at 12:11
  • @Thomas you must save this connection string in correct format in connectionStrings section in config file and provide name of this connection in InitializeDatabaseConnection method. So in you case: WebSecurity.InitializeDatabaseConnection(@"DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true); – DrAlligieri Sep 03 '15 at 12:15
  • why LazyInitializer.EnsureInitialized() also throw error which i post here the message. – Thomas Sep 03 '15 at 12:18
  • @Thomas for LazyInitializer.EnsureInitialized to see real error - expand Details of exception and watch Internal Exception because provided there exception are general exception which are thrown when code throws error in other threads/delegates (which really LazyInitializer consumes). – DrAlligieri Sep 03 '15 at 12:31