Click here to Skip to main content
15,849,996 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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


What I have tried:

connection string is issue so what is the problem on my connection
Posted
Updated 31-Oct-22 0:25am
Comments
Graeme_Grant 28-Oct-22 21:21pm    
Did you set a breakpoint before the error to see what is being passed?
Dave Kreskowiak 29-Oct-22 0:05am    
The first thing I would try is getting rid of the square brackets in your "data source" and "initial catalog" parts of the connection string.

Next, are you running a named instance of SQL Server on the DESKTOP-L558MLK server?
Member 15627495 29-Oct-22 5:04am    
a connection string is more than a 'path' , there are 'settings in' depending the db.

I see in call stack that you use 'path.combine(...)', It's a function related to path ( hard drive / network / system file ) ... but not for a connection string to db.
ahmed_sa 29-Oct-22 11:35am    
so what i do to solve issue

1 solution

You're passing an Entity Framework connection string to a class which expects a SQL Server connection string. You need to extract the SQL Server connection string and pass that in instead.

For example:
C#
new EntityConnectionStringBuilder(outerConnectionString).ProviderConnectionString
See EntityConnectionStringBuilder[^]

NB: Your application should almost certainly NOT be connecting to SQL Server using the sa account. That is an unlimited superuser account, which has far more permissions than almost any application ever requires. Instead, create a specific user account for your application, grant it only the permissions required by your application, and connect using that account instead.

Also, if that's your real sa password, then change it immediately to a strong randomly-generated password. At the moment, you've left your front door wide open with a small note pinned to the door saying "Burglars: please don't steal my stuff".
 
Share this answer
 
Comments
ahmed_sa 31-Oct-22 18:13pm    
only one question please connection string will be
server=DESKTOP-L558MLK\AHMEDSALAHSQL,database=testdata_Dev,userid=sa and password=321
OR
using connection string

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;persist security info=True;user id=sa;password=321;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient"
Richard Deeming 1-Nov-22 4:36am    
The one that starts server=... is the SQL Server connection string. The one that starts metadata=... is the Entity Framework 6 connection string.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900