Solved

Can't create users table in existing DB

Posted on 2016-09-25
16
60 Views
Last Modified: 2016-09-30
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
Comment
Question by:ma701sss
  • 10
  • 6
16 Comments
 
LVL 35

Expert Comment

by:David Todd
ID: 41815192
Hi,

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

Regards
  David
0
 

Author Comment

by:ma701sss
ID: 41816864
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
 
LVL 35

Expert Comment

by:David Todd
ID: 41816874
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
 

Author Comment

by:ma701sss
ID: 41816967
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
 

Author Comment

by:ma701sss
ID: 41817981
David, you there?
0
 
LVL 35

Expert Comment

by:David Todd
ID: 41819089
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
 

Author Comment

by:ma701sss
ID: 41819265
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
 

Author Comment

by:ma701sss
ID: 41820681
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 35

Expert Comment

by:David Todd
ID: 41821049
Hi,

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

HTH
  David
0
 

Author Comment

by:ma701sss
ID: 41821469
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
 

Author Comment

by:ma701sss
ID: 41822767
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
 
LVL 35

Accepted Solution

by:
David Todd earned 500 total points
ID: 41822849
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
 
LVL 35

Expert Comment

by:David Todd
ID: 41822850
PS Check the SQL log - maybe the connection itself is failing.
0
 

Author Comment

by:ma701sss
ID: 41824232
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
 

Author Comment

by:ma701sss
ID: 41824341
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
 

Author Closing Comment

by:ma701sss
ID: 41824342
Many thanks
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now