2

我正在使用以下链接中的步骤来创建自定义 Create_User_Wizard,但我遇到了一些 METADATA 错误。有人可以帮帮我吗?

http://weblogs.asp.net/gurusakar/archive/2009/01/27/storing-user-profile-into-a-custom-table-using-createuser-wizard-control.aspx

以下是我在 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=&quot;data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\ASPNETDB.MDF;integrated security=True;user instance=True;multipleactiveresultsets=False;App=EntityFramework&quot;" 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
4

1 回答 1

2

看到您的错误行号:45,您的实体框架和 Ado.net 连接似乎都使用相同的连接字符串:SqlConnection

您上面显示的 ConnectionString 是您的实体框架。不要将它用于您的 ADO.NET 连接。

ADO.NET 连接字符串示例如下:

"data source=FLOP-PC\Practice;initial catalog=Northwind;integrated security=True"

简而言之,您需要两个连接字符串,一个用于您的实体框架(已经存在)和一个用于您的 ADO.Net 部分的新字符串。

于 2013-07-28T15:00:19.760 回答