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  
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,415 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,308 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Zhanglong Wu-MSFT 261 Reputation points Microsoft Vendor
    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