Create database table for user accounts

foonfosiusa

New Member
I needed to create a custom database to store additional user information when a new user registers with our site. I have created a table called "UserProfile". Here is some code to start with:web.config file:\[code\]<connectionStrings> <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\Database1.mdf;User Instance=true" providerName="System.Data.SqlClient" /> <add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" /></connectionStrings>\[/code\]I have changed the database I want to use in the App_Data folder from "aspnetdb.mdf" to "Database1.mdf" and now it will never create the user. Here's my created user code from the CreateUserWizard (modified for some additional fields):\[code\]protected void RegisterUser_CreatedUser(object sender, EventArgs e) { // Get the UserId of the just-added user MembershipUser newUser = System.Web.Security.Membership.GetUser(RegisterUser.UserName); Guid newUserId = (Guid)newUser.ProviderUserKey; //Get Profile Data Entered by user in CUW control String FirstName = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("FirstName")).Text; String LastName = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("LastName")).Text; String Company = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("CompanyName")).Text; String PartsList = ((DropDownList)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("companyddl")).SelectedValue; String UserName = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("UserName")).Text; String Password = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("Password")).Text; String Email = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("Email")).Text; String Question = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("Question")).Text; String Answer = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("Answer")).Text; // Insert a new record into User_Profile if (Company == "OurCompany" || Company == "OurCompany, Inc.") { Roles.AddUserToRole(UserName, "manager"); UserRole = "manager"; } if (PartsList == "SF") { Roles.AddUserToRole(UserName, "user_sf"); UserRole = "user_sf"; } if (PartsList == "TL") { Roles.AddUserToRole(UserName, "user_tl"); UserRole = "user_tl"; } // Get your Connection String from the web.config. MembershipConnectionString is the name I have in my web.config string connectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString; string insertSql = "INSERT INTO ApplicationServices.UserProfile(UserId,FirstName, LastName, Company, PartsList, UserName, Password, Email, Question, Answer, UserRole)" + "VALUES(@FirstName, @LastName, @Company, @Partslist, @UserName, @Password, @Email, @Question, @Answer, @UserRole)"; using (SqlConnection myConnection = new SqlConnection(connectionString)) { myConnection.Open(); SqlCommand myCommand = new SqlCommand(insertSql, myConnection); myCommand.Parameters.AddWithValue("@FirstName", FirstName); myCommand.Parameters.AddWithValue("@LastName", LastName); myCommand.Parameters.AddWithValue("@Company", Company); myCommand.Parameters.AddWithValue("@PartsList", PartsList); myCommand.Parameters.AddWithValue("@UserName", UserName); myCommand.Parameters.AddWithValue("@Password", Password); myCommand.Parameters.AddWithValue("@Email", Email); myCommand.Parameters.AddWithValue("@Question", Question); myCommand.Parameters.AddWithValue("@Answer", Answer); myCommand.Parameters.AddWithValue("@Role", UserRole); myCommand.ExecuteNonQuery(); myConnection.Close(); } }\[/code\]The error I'm getting is:\[code\]Exception Details: System.Data.SqlClient.SqlException: Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion'.\[/code\]If I change it back to the aspnetdb.mdf I get an error on the line\[code\]myCommand.ExecuteNonQuery();\[/code\]that says Invalid object name 'UserProfile (which makes sense because it's the wrong database, or am I thinking wrong?)
 
Back
Top