我正在使用以下链接中的步骤来创建自定义 Create_User_Wizard,但我遇到了一些 METADATA 错误。有人可以帮帮我吗?
以下是我在 WEB.CONFIG 文件中使用的连接:
<add name="ASPNETDBEntities" connectionString="metadata=res://*/App_Code.ASPNETDB.csdl|res://*/App_Code.ASPNETDB.ssdl|res://*/App_Code.ASPNETDB.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\ASPNETDB.MDF;integrated security=True;user instance=True;multipleactiveresultsets=False;App=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings>
我在后面的代码中使用以下代码enter code here
//protected void CreateUserWizard2_CreatedUser(object sender, EventArgs e)
{
// get the user id of the just created user before the final profile is created
MembershipUser newUser = Membership.GetUser(CreateUserWizard2.UserName);
Guid newUserId = (Guid)newUser.ProviderUserKey;
//Get Profile Data Entered by user in CUW control
String Country =
((TextBox)CreateUserWizard2.CreateUserStep.ContentTemplateContainer.FindControl("Country")).Text;
// Insert a new record into User_Profile
// Get your Connection String from the web.config. MembershipConnectionString is the name I have in my web.config
string connectiontest = ConfigurationManager.ConnectionStrings["ASPNETDBEntities"].C
onnectionString;
string insertSql = "INSERT INTO User_Profile(UserId,Country) VALUES(@UserId, @Country)";
using (SqlConnection myConnection = new SqlConnection(connectiontest))
{
myConnection.Open();
SqlCommand myCommand = new SqlCommand(insertSql, myConnection);
myCommand.Parameters.AddWithValue("@UserID", newUserId);
myCommand.Parameters.AddWithValue("@Country", Country);
myCommand.ExecuteNonQuery();
myConnection.Close();
}
}
一切正常,但是当我单击“创建用户”按钮时,所有数据都从现有字段中插入,但我创建的新字段中的数据没有插入到数据库中,并且它抛出与以下相关的错误一些元数据不支持:
单击“创建用户”按钮后,我收到以下错误
“/”应用程序中的服务器错误。
不支持关键字:“元数据”。
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Keyword not supported: 'metadata'.
Source Error:
Line 43:
Line 44:
**Line 45: using (SqlConnection myConnection = new SqlConnection(connectiontest))**
Line 46:
Line 47: {
Source File: d:\Decto Web Project\TND\Default.aspx.cs Line: 45
Stack Trace:
[ArgumentException: Keyword not supported: 'metadata'.]
System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) +5055124
System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) +98
System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) +64
System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) +24
System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(String connectionString, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) +150
System.Data.SqlClient.SqlConnection.ConnectionString_Set(String value) +59
System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) +4
System.Data.SqlClient.SqlConnection..ctor(String connectionString) +26
TND_Default.CreateUserWizard2_CreatedUser(Object sender, EventArgs e) in d:\Decto Web Project\TND\Default.aspx.cs:45
System.Web.UI.WebControls.CreateUserWizard.OnCreatedUser(EventArgs e) +118
System.Web.UI.WebControls.CreateUserWizard.AttemptCreateUser() +341
System.Web.UI.WebControls.CreateUserWizard.OnNextButtonClick(WizardNavigationEventArgs e) +111
System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs e) +413
System.Web.UI.WebControls.CreateUserWizard.OnBubbleEvent(Object source, EventArgs e) +121
System.Web.UI.WebControls.WizardChildTable.OnBubbleEvent(Object source, EventArgs args) +19
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +125
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +167
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563