-->

Connection string error using membership provider

2019-05-26 03:00发布

问题:

The target is: I need a wcf method which will create user in the database.

I am using membership provider. and My client is SmartPhone/mobile device.

I wrote a method which will create user BUT when I test the method I get the following error.

error:

An error occurred while attempting to initialize a System.Data.SqlClient.SqlConnection object. The value that was provided for the connection string may be wrong, or it may contain an invalid syntax. Parameter name: connectionString

And I get this error in the following line:

Membership.CreateUser(name, password,email,"question","answer",true,out createStatus);

I am using the same connectionString that I use to read data from the database.

My connection string is:

<add name="MajangoEntities" connectionString="metadata=res://*/EntityModel.MajangoEntityModel.csdl|res://*/EntityModel.MajangoEntityModel.ssdl|res://*/EntityModel.MajangoEntityModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=tcp:sql2k298.discountasp.net;initial catalog=SQL2008R2_835021_myddb;user id=SQL2008R2_835021_mydb_user;password=mypassword;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

Can anybody help me with some ideas??

回答1:

That connection string includes some Entity Framework specific data. Try instead just the "provider connection string" embedded within it:

 <add name="MajangoEntities" connectionString="data source=tcp:sql2k298.discountasp.net;initial catalog=SQL2008R2_835021_myddb;user id=SQL2008R2_835021_mydb_user;password=mypassword;multipleactiveresultsets=True;App=EntityFramework">

The rest of the data in there (the metadata, etc.) is just confusing SQL Server.