• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 111
  • Last Modified:

Can't create users table in existing DB

I've followed this tutorial:

http://www.asp.net/identity/overview/getting-started/adding-aspnet-identity-to-an-empty-or-existing-web-forms-project

All worked OK up to creating the new database and ASPNetUsers table. Instead of creating defaultconnection as instructed in this tutorial, I edited defaultconnection to point to an existing db. I expected the new table to be created automatically when registering a new user but it doesn't and the only error I receive when submitting the form in Register.aspx is "Name cannot be null or empty". How can I achieve what I'm trying to do?

Thanks
0
ma701sss
Asked:
ma701sss
  • 10
  • 6
1 Solution
 
David ToddSenior DBACommented:
Hi,

Okay, what happens if you use the default connection as instructed in the tututorial?

Regards
  David
0
 
ma701sssAuthor Commented:
Hi,

Thanks for responding. I get the same message. I don't even know where it's trying to create a database here:

<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\WebFormsIdentity.mdf;Initial Catalog=WebFormsIdentity;Integrated Security=True"
               providerName="System.Data.SqlClient" />

Open in new window


My defaultconnection string to connect to my db in SQL Server 2014 is as follows:

<add name="DefaultConnection" connectionString="Data Source=xxxxx\SQLEXPRESS2014;Initial Catalog=xx;Integrated Security=True" providerName="System.Data.SqlClient" />-->

Open in new window

0
 
David ToddSenior DBACommented:
Hi,

The logon you are using will need the create database permission. What server roles does your login have on the server(s)?

Regards
  David
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
ma701sssAuthor Commented:
David, please could you explain what I need to check in management studio (under "users" or "roles")? I have been connecting to and working with tables no problem until now, maybe you have hit the nail on the head, i.e. I don't have permission to create a table from within the application but I've not dealt with that yet.
0
 
ma701sssAuthor Commented:
David, you there?
0
 
David ToddSenior DBACommented:
Hi,

It occurs to me that the sampel assumes you are a member of the sysadmin role.

In SSMS, Open Object Explorer on the instance in question, find security, expand logins, right click on the login of interest and select properties. Select Server Roles, and tick sysadmin ... Click OK as necessary

Regards
  David
0
 
ma701sssAuthor Commented:
Hi,

The problem right now is that I don't understand which role I need to select. I have been using integrated security with my windows login. e.g. "ma701ss" but I don't know what this maps to in SSMS.
0
 
ma701sssAuthor Commented:
I go to Security > Users > IISAPPPOOL\jb then click on properties. There is nothing there called sysadmin under "Membership" just db_owner, db_securityadmin, etc.
0
 
David ToddSenior DBACommented:
Hi,

You're looking at security under the database. Look at security under the server.

HTH
  David
0
 
ma701sssAuthor Commented:
Thanks, I'll have to check later today. Is it likely to be permissions though, as I can insert into existing tables, so presumably there is write access to the db from within my app?
0
 
ma701sssAuthor Commented:
Hi, I tried that tonight, it didn't work. I ended up ticking all options under server roles just to test it, still didn't work.
0
 
David ToddSenior DBACommented:
Hi,

Ticking everything is overdoing it. sysadmin can do everything. Suggest then, that you need to use SQL profiler to see what is being attempted.

HTH
  David
0
 
David ToddSenior DBACommented:
PS Check the SQL log - maybe the connection itself is failing.
0
 
ma701sssAuthor Commented:
Hi, I tried the SQL profiler (first time using this) and I could see that when submitting the page giving the null error, there is no call to SQL Server. There must be a problem with the aspx files. I've pasted the code below, as I can't see anything obvious.

register.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="~/vb/register.aspx.vb" Inherits="WebFormsIdentity.Register" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
     <form id="form1" runat="server">
    <div>
        <h4 style="font-size: medium">Register a new user</h4>
        <hr />
        <p>
            <asp:Literal runat="server" ID="StatusMessage" />
        </p>                
        <div style="margin-bottom:10px">
            <asp:Label runat="server" AssociatedControlID="UserName">User name</asp:Label>
            <div>
                <asp:TextBox runat="server" ID="UserName" />                
            </div>
        </div>
        <div style="margin-bottom:10px">
            <asp:Label runat="server" AssociatedControlID="Password">Password</asp:Label>
            <div>
                <asp:TextBox runat="server" ID="Password" TextMode="Password" />                
            </div>
        </div>
        <div style="margin-bottom:10px">
            <asp:Label runat="server" AssociatedControlID="ConfirmPassword">Confirm password</asp:Label>
            <div>
                <asp:TextBox runat="server" ID="ConfirmPassword" TextMode="Password" />                
            </div>
        </div>
        <div>
            <div>
                <asp:Button runat="server" OnClick="CreateUser_Click" Text="Register" />
            </div>
        </div>
    </div>
    </form>
</body>
</html>

Open in new window


register.aspx.vb
Imports Microsoft.AspNet.Identity
Imports Microsoft.AspNet.Identity.EntityFramework
Imports System
Imports System.Linq

Namespace WebFormsIdentity

    Public Class Register
        Inherits System.Web.UI.Page

        Protected Sub CreateUser_Click(ByVal sender As Object, ByVal e As EventArgs)
            ' Default UserStore constructor uses the default connection string named: DefaultConnection
            Dim userStore = New UserStore(Of IdentityUser)
            Dim manager = New UserManager(Of IdentityUser)(userStore)
            Dim user = New IdentityUser
            Dim result As IdentityResult = manager.Create(user, Password.Text)
            If result.Succeeded Then
                StatusMessage.Text = String.Format("User {0} was created successfully!", user.UserName)
            Else
                StatusMessage.Text = result.Errors.FirstOrDefault
            End If

        End Sub
    End Class
End Namespace

Open in new window


The error I'm getting is "Name cannot be null or empty".
0
 
ma701sssAuthor Commented:
I figured it out, in the vb files above, I added the following to line 16:

user.UserName = UserName.Text

Open in new window


Thanks for your help.
0
 
ma701sssAuthor Commented:
Many thanks
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 10
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now