1

I am trying to get my custom "CREATEUSER" to work but I think I'm having problems in my web.config. Thanks to help here, I've gotten the MEMBERSHIP section written but my MEMBERSHIP.CREATEUSER command is failing to logon to the database. The error is, "Cannot logon to the default database." I've added a connection string and the name is in my section. But I'm stuck.

Here is the code-behind file for creating the user:

        protected void submit_Click(object sender, EventArgs e)
        {

                Membership.CreateUser(userName.Text, passwdConfirm.Text, email.Text);

        }

And, here is my Web.config file.

<configuration>

  <connectionStrings>
      <add name="FVTCEntities" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=SFP;attachdbfilename=H:\ASP.Net\FVRG\FVRG\App_Data\FVTC.mdf;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
      <add name="dbMembership" connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=H:\ASP.Net\FVRG\FVRG\App_Data\ASPNETDB.MDF;User Instance=true" providerName="System.Data.SqlClient" />
  </connectionStrings>
    <system.web>
        <authorization>
            <allow roles="ADMIN" />
            <allow roles="GUEST" />
        </authorization>
        <roleManager enabled="true" />
        <authentication mode="Forms" />
        <compilation debug="true" targetFramework="4.0" />

      <membership>

        <providers>
          <clear/>
          <add name="AspNetSqlMembershipProvider"
                type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
                connectionStringName="dbMembership"
                enablePasswordRetrieval="false"
                enablePasswordReset="true"
                requiresQuestionAndAnswer="false"
                requiresUniqueEmail="true"
                passwordFormat="Hashed"
                maxInvalidPasswordAttempts="5"
                minRequiredPasswordLength="7"
                minRequiredNonalphanumericCharacters="1"
                passwordAttemptWindow="10"
                passwordStrengthRegularExpression=""
                applicationName="/FVRG" />
        </providers>

      </membership>
    </system.web>

  <appSettings>
    <add key="DatabaseConnection" value="Data Source=.\SQLEXPRESS;AttachDbFilename=H:\ASP.Net\FVRG\FVRG\App_Data\FVTC.mdf;Integrated Security=True;User Instance=True" />
  </appSettings>
</configuration>

thanks in advance for your help!

Susan
  • 1,822
  • 8
  • 47
  • 69
  • 1
    can you confirm that the connection string is correct? the conncectionStringName that you specify is "dbMembership" but I can't see it since you only include the in your code. – atbebtg Aug 10 '11 at 15:32
  • I've inserted the full Web.config file. – Susan Aug 10 '11 at 15:42

1 Answers1

1

That error typically arises because of the account being used to access the database. Each account setup in the database is given a default database, and the default database setup for this user either does not exist, or the user does not have access to it. This has to be done on the database server.

HTH.

Brian Mains
  • 50,520
  • 35
  • 148
  • 257
  • I've pasted in the full Web.config whhich does show the connection string. I'm using SQLExpress as my SQL server, how do you go about adding user access? It does show up as a DB in my list of databases in Server Explorer. – Susan Aug 10 '11 at 15:45
  • Oh I missed it. If you haven't mucked with the database, I'm not sure why you are getting the error then, because if you would have read that you would have known the error. Maybe the error is the database isn't attaching right. What it's saying is that the default database is a database the currently logged on user to the SQL database can't be read..... The error is similar to this: http://weblogs.asp.net/jeffwids/archive/2010/02/19/how-to-change-sql-server-login-default-database-through-sql-script.aspx – Brian Mains Aug 10 '11 at 16:10
  • Hi Brian ... can you be logged into/attached to 2 different SALExplress databases at the same time? I have my FVTC (restaurant) database and my ASPNETDB (membership provider) database. Do I need to manage connecting/unconnecting? It all seems to work if I don't use my custom createuser control. – Susan Aug 10 '11 at 16:29
  • No you shouldn't, but I don't know how multiple database attachments would work; you can script over all the membership tables into your FVTC database though, using the aspnet_regsql.exe utility. – Brian Mains Aug 10 '11 at 16:56