error Illegal characters in path when get connection string from entity framework ?

ahmed salah 3,216 Reputation points
2022-10-28T23:04:11.537+00:00

I work on entity framework on web application

i get error when get connection string

connection string as below :

metadata=res://*/ERPEntities.csdl|res://*/ERPEntities.ssdl|res://*/ERPEntities.msl;provider=System.Data.SqlClient;provider connection string='data source=[DESKTOP-L558MLK\AHMEDSALAHSQL];initial catalog=[testdata_Dev];user id=sa;password=321;MultipleActiveResultSets=True;App=EntityFramework'  

line generate error

WebSecurity.InitializeDatabaseConnection(connectionstr, "UserProfiles", "userID", "userName", autoCreateTables: false);

full details error

   at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)  
   at System.IO.Path.Combine(String path1, String path2)  
   at WebMatrix.Data.ConfigurationManagerWrapper.GetConnection(String name, Func`2 getConfigConnection, Func`2 fileExists)  
   at WebMatrix.Data.ConfigurationManagerWrapper.GetConnection(String name)  
   at WebMatrix.Data.Database.OpenNamedConnection(String name, IConfigurationManager configurationManager)  
   at WebMatrix.Data.Database.Open(String name)  
   at WebMatrix.WebData.DatabaseConnectionInfo.Connect()  
   at WebMatrix.WebData.SimpleMembershipProvider.ConnectToDatabase()  
   at WebMatrix.WebData.SimpleMembershipProvider.ValidateUserTable()  
   at WebMatrix.WebData.WebSecurity.InitializeMembershipProvider(SimpleMembershipProvider simpleMembership, DatabaseConnectionInfo connect, String userTableName, String userIdColumn, String userNameColumn, Boolean createTables, SimpleMembershipProviderCasingBehavior casingBehavior)  
   at WebMatrix.WebData.WebSecurity.InitializeProviders(DatabaseConnectionInfo connect, String userTableName, String userIdColumn, String userNameColumn, Boolean autoCreateTables, SimpleMembershipProviderCasingBehavior casingBehavior)  
   at WebMatrix.WebData.WebSecurity.InitializeDatabaseConnection(String connectionStringName, String userTableName, String userIdColumn, String userNameColumn, Boolean autoCreateTables, SimpleMembershipProviderCasingBehavior casingBehavior)  
   at WebMatrix.WebData.WebSecurity.InitializeDatabaseConnection(String connectionStringName, String userTableName, String userIdColumn, String userNameColumn, Boolean autoCreateTables)  
   at TTERP.Web.MvcApplication.Session_Start(Object sender, EventArgs e) in G:\ERP WEB software\Erp web software\workspace\TTERP.Web\Global.asax.cs:line 78  
Developer technologies .NET Other
Developer technologies C#
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2022-10-31T07:25:24.08+00:00

    @ahmed salah ,

    Please check the document of InitializeDatabaseConnection, the first parameter is the name of connection string instead of connection string.

    Parameters
    connectionStringName
    String
    The name of the connection string for the database that contains user information. If you are using SQL Server Compact, this can be the name of the database file (.sdf file) without the .sdf file name extension.

    Best regards,
    Zhanglong


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.