Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.Net Setting the correct Connection String when calling Membership.CreateUser()
    primarykey
    data
    text
    <p>This is a continuation of my last question: "Internal Database - ASP.NET Auto Web Site Registration on User Creation". I am running the following code. This is just a test block of code. It works but my problem is it creates the default SQLEXPRESS ASPNETDB.MDF in the App_Data Directory. This is not what I want.</p> <pre><code>// Create a MembershipCreateStatus Status for Reporting... MembershipCreateStatus status = new MembershipCreateStatus(); // Setup SqlMembershipProvider for Initialization... SqlMembershipProvider sqlProvider = new SqlMembershipProvider(); // Setup a NameValueCollection... NameValueCollection config = new NameValueCollection(); // Set the Connection Name of the SQL Connection String... string SQLDBNameString = "My Company Database.Properties.Settings.ConnectionString"; // Update the private connection string field in the base class. string connectionString = "Data Source=Server;Initial Catalog=’My Company Database';User ID=USERNAME;Password=PASSWORD"; // Username of the account to add... string username = "User121"; // Generate a dynamic Password.... string password = Membership.GeneratePassword(8, 1); // Email Address of the User... string email = "email@email.com"; try { string Name = "My Company Database"; config.Add("applicationName", "My Company Database"); config.Add("maxInvalidPasswordAttempts", "5"); config.Add("passwordAttemptWindow", "10"); config.Add("minRequiredPasswordLength", "8"); config.Add("passwordStrengthRegularExpression", ""); config.Add("enablePasswordReset", "True"); config.Add("enablePasswordRetrieval", "False"); config.Add("requiresQuestionAndAnswer", "False"); config.Add("requiresUniqueEmail", "True"); config.Add("passwordFormat", "Hashed"); config.Add("connectionStringName", SQLDBNameString); sqlProvider.Initialize(Name, config); ConnectionStringSettings ConnectionStringSettings = ConfigurationManager.ConnectionStrings[SQLDBNameString]; if ((ConnectionStringSettings == null) || (ConnectionStringSettings.ConnectionString.Trim() == String.Empty)) { throw new Exception("Connection string cannot be blank."); } // connectionString = ConnectionStringSettings.ConnectionString; MembershipUser newUser = Membership.CreateUser(username, password, email, "Whats My Password", password, true, out status); } catch (Exception ex) { String message = "Error...\r\n\r\n" + ex.ToString(); String caption = "Error"; MessageBoxButtons button = MessageBoxButtons.OK; MessageBoxIcon icon = MessageBoxIcon.Asterisk; MessageBox.Show(message, caption, button, icon); } MessageBox.Show("Account Creation : " + status.ToString() + "\r\n" + "Username is : " + username + "\r\n" + "Password is : " + password + "\r\n" + "Email : " + email); </code></pre> <p>This code is running in a C# Application, SQL Front end database and it is supposed to automatically create a user so they can login to a web page once I have added them to my database. This Code is not running in a ASP Website Application. My "config" is not being initalised from what I can see. Any help is much appreaciated!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload