Elvis
Elvis

Reputation: 29

Storing User Profile into a Custom Table using CreateUser Wizard control

I am using the steps from below link, to create a custom Create_User_Wizard, but I am getting some METADATA Errors. Can someone please help me?

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

BELOW IS THE CONNECTION THAT I AM USING IN WEB.CONFIG FILE:

<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>

I AM USING THE BELOW CODE IN CODE BEHINDenter 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();
            }
        }

Everything is working just fine but the moment I click on "Create User" Button all the data gets INSERTED from the existing fields but the data's from new fields that I have created are not getting inserted into the database and it is throwing below error relating to some METADATA not supported:

I AM GETTING THE BELOW ERROR ONCE I CLICK THE CREATE USER BUTTON

Server Error in '/' Application.

Keyword not supported: '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

Upvotes: 2

Views: 276

Answers (1)

R.C
R.C

Reputation: 10565

Seeing you Error Line No: 45, It seems you are using the same connection string for both your Entity Framework as well as for your Ado.net connection: SqlConnection.

The ConnectionString you have shown above is of your Entity FRamework. Do not use it for your ADO.NET connection.

A sample ADO.NET connection string will be like:

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

In short you need two connections strings, One for your Entity FRamework ( already present) & a new one for your ADO.Net section.

Upvotes: 2

Related Questions