我正在使用下面的步骤链接,创建一个自定义的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();
}
}
一切正常,但是当我点击“创建用户”按钮时,所有数据都会从现有字段中被插入,但是我创建的新字段中的数据没有插入到数据库中,而是在下面投入与某些METADATA相关的错误不受支持:
我收到了以下错误,我点击创建用户按钮
“/”应用程序中的服务器错误。
不支持关键字:'元数据'。
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
答案 0 :(得分:2)
看到错误行号:45,您的实体框架和Ado.net连接似乎都使用相同的连接字符串:SqlConnection
。
您在上面显示的ConnectionString是您的Entity FRamework。不要用它来做你的 ADO.NET连接。
示例ADO.NET连接字符串将类似于:
"data source=FLOP-PC\Practice;initial catalog=Northwind;integrated security=True"
简而言之,您需要两个连接字符串,一个用于您的实体FRamework(已存在)&amp;一个新的ADO.Net部分。