Solved

Can't create users table in existing DB

Posted on 2016-09-25
16
102 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how the fundamental information of how to create a table.

627 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