Showing posts with label membership. Show all posts
Showing posts with label membership. Show all posts

Thursday, March 8, 2012

AssignExpression In For Loop Container

What I'm trying to do is take multiple "snapshots" of a membership for many months. I was trying to do this in a For Loop Container in which I added one to the month variable and subtracted one from an iteration variable each loop, unless the month variable = 13...then I would add one to the year variable, set the month variable to 1 and subtract one from the iteration variable. This, I was hoping, would allow me to initialize 24 to the iteration variable, 1 to the month variable and 2004 to the year variable, kick off the package, and get 2 years worth of "snapshots" in seperate files (one for each month). Here is the AssignExpression I thought would work:

@.Member_Month == 13 ? @.Member_Month = 1 && @.Member_Year= @.Member_Year + 1 && @.Member_Iteration = @.Member_Iteration - 1 : @.Member_Month = @.Member_Month + 1 && @.Member_Iteration = @.Member_Iteration - 1

The package states that the single "=" should be double, but I don't think that that is what I want to do (I tried doing this just to check, and it didn't like this either). I think that it is having problems with doing multiple things on both sides of the ":". What am I doing wrong?

Thanks,

Brian Layden

The AssignExpression supports only a single assignment. Can you put the logic of updating Month and Year inside the loop in a script, perhaps?

Friday, February 24, 2012

aspnet_regsql.exe - cannot insert null values

Im trying to setup a SQL server 2000 database to use membership & roles. Running aspnet_regsql.exe gives me the following errors

Setup failed.

Exception:
An error occurred during the execution of the SQL file 'InstallCommon.sql'. The SQL error number is 515 and the SqlException message is: Cannot insert the value NULL into column 'Column', table 'tempdb.dbo.#aspnet_Permissions_________________________________________________________________________________________________000000008000'; column does not allow nulls. INSERT fails.
Warning: Null value is eliminated by an aggregate or other SET operation.
The statement has been terminated.

------------
Details of failure
------------

SQL Server:
Database: [AddressVerification]
SQL file loaded:
InstallCommon.sql

Commands failed:

CREATE TABLE #aspnet_Permissions
(
Owner sysname,
Object sysname,
Grantee sysname,
Grantor sysname,
ProtectType char(10),
[Action] varchar(20),
[Column] sysname
)

INSERT INTO #aspnet_Permissions
EXEC sp_helprotect

IF (EXISTS (SELECT name
FROM sysobjects
WHERE (name = N'aspnet_Setup_RestorePermissions')
AND (type = 'P')))
DROP PROCEDURE [dbo].aspnet_Setup_RestorePermissions


SQL Exception:
System.Data.SqlClient.SqlException: Cannot insert the value NULL into column 'Column', table 'tempdb.dbo.#aspnet_Permissions_________________________________________________________________________________________________000000008000'; column does not allow nulls. INSERT fails.
Warning: Null value is eliminated by an aggregate or other SET operation.
The statement has been terminated.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at System.Web.Management.SqlServices.ExecuteFile(String file, String server, String database, String dbFileName, SqlConnection connection, Boolean sessionState, Boolean isInstall, SessionStateType sessionStatetype)


Ive run this many times on other servers and have never come across this problem before. Has anyone else ? Does anyone know the cause and if there is a fix ??

** I am logged in with full admin privaliges

tia

Mark.

This is because the preinstalled user defined data type sysname by default does not allow nulls--that means column of sysname data type won't accept nulls unless you explicitly set the column to allow null in column definition. So if the sp_helprotect stored procedure returns some rows with nulls in the [column] field (this is an rare issue but it does exist), the insert command will fail. So here I have to say it is a flaw of the aspnet_regsql utility.|||

I wrote a simple script to update the system table systypes to make sysname data type to accept NULLs. However the script is not fully tested and since it modifies system table directly, I don't recommend to use it and you need to consider the potential risk when using it. If some issue is caused by the script, please pass 'NoNulls' as parameter to change the systypes back to default:

CREATE PROCEDURE usp_KillUsers
@.p_DBName SYSNAME = NULL
AS

/* Check Paramaters */
/* Check for a DB name */
IF (@.p_DBName IS NULL)
BEGIN
PRINT 'You must supply a DB Name'
RETURN
END -- DB is NULL
IF (@.p_DBName = 'master')
BEGIN
PRINT 'You cannot run this process against the master database!'
RETURN
END -- Master supplied
IF (@.p_DBName = DB_NAME())
BEGIN
PRINT 'You cannot run this process against your connections database!'
RETURN
END -- your database supplied

SET NOCOUNT ON

/* Declare Variables */
DECLARE @.v_spid INT,
@.v_SQL NVARCHAR(255)

/* Declare the Table Cursor (Identity) */
DECLARE c_Users CURSOR
FAST_FORWARD FOR
SELECT spid
FROM master..sysprocesses (NOLOCK)
WHERE db_name(dbid) = @.p_DBName

OPEN c_Users

FETCH NEXT FROM c_Users INTO @.v_spid
WHILE (@.@.FETCH_STATUS <> -1)
BEGIN
IF (@.@.FETCH_STATUS <> -2)
BEGIN
SELECT @.v_SQL = 'KILL ' + CONVERT(NVARCHAR, @.v_spid)
-- PRINT @.v_SQL
EXEC (@.v_SQL)
END -- -2
FETCH NEXT FROM c_Users INTO @.v_spid
END -- While

CLOSE c_Users
DEALLOCATE c_Users

CREATE PROCEDURE sp_SetSysnameAllowNulls @.Operation varchar(10)='AllowNulls'
AS
BEGIN
DECLARE @.cmd nvarchar(4000)
EXEC sp_configure 'allow updates',1
RECONFIGURE WITH OVERRIDE
EXEC sp_msforeachdb N'use[?];
IF (DATABASEPROPERTY(db_name(),''IsReadOnly'')=1)
BEGIN
declare @.dbname sysname;
set @.dbname=db_name();
use master
EXEC usp_KillUsers @.dbname;
EXEC sp_dboption @.dbname,''read only'',''false'';
END'

IF (@.Operation = 'AllowNulls')
EXEC sp_msforeachdb N'use [?];
IF NOT EXISTS(SELECT 1 FROM systypes WHERE name=''sysname'')
PRINT ''sysname data type not found in''+ DB_NAME()
ELSE
UPDATE systypes SET status=status-1
WHERE name=''sysname'' AND (status&1)=1'
ELSE
IF (@.Operation = 'NoNulls')
EXEC sp_msforeachdb N'use [?];
IF NOT EXISTS(SELECT 1 FROM systypes WHERE name=''sysname'')
PRINT ''sysname data type not found in''+ DB_NAME()
ELSE
UPDATE systypes SET status=status+1
WHERE name=''sysname'' AND (status&1)=0'
ELSE RAISERROR('Expected @.Opertaion=''AllowNulls'' or ''NoNulls''',16,1)
EXEC sp_configure 'allow updates',0
RECONFIGURE WITH OVERRIDE
END

Monday, February 13, 2012

ASP.NET Membership tables dissappear when db is attached to a different sql server instanc

A SQL Server 2005 (developer edition) database contains both application
data tables and ASP.NET membership tables and stored procedures and runs
without error on computer A. When the database is detached, copied to
computer B, and re-attached, the ASP.NET membership tables and stored
procedures are gone. If you know the cause/cure for this issue, I would
appreciate your help.
Thanks,
Keith
Are they gone, or just not visible? It could be a permissions issue
where you're connecting with elevated permissions on A and not on B.
--Mary
On Sat, 24 Feb 2007 22:22:06 -0800, "keith" <kbrickey@.dslextreme.com>
wrote:

>A SQL Server 2005 (developer edition) database contains both application
>data tables and ASP.NET membership tables and stored procedures and runs
>without error on computer A. When the database is detached, copied to
>computer B, and re-attached, the ASP.NET membership tables and stored
>procedures are gone. If you know the cause/cure for this issue, I would
>appreciate your help.
>Thanks,
>Keith
>

ASP.NET Membership tables dissappear when db is attached to a different sql server instanc

A SQL Server 2005 (developer edition) database contains both application
data tables and ASP.NET membership tables and stored procedures and runs
without error on computer A. When the database is detached, copied to
computer B, and re-attached, the ASP.NET membership tables and stored
procedures are gone. If you know the cause/cure for this issue, I would
appreciate your help.
Thanks,
KeithAre they gone, or just not visible? It could be a permissions issue
where you're connecting with elevated permissions on A and not on B.
--Mary
On Sat, 24 Feb 2007 22:22:06 -0800, "keith" <kbrickey@.dslextreme.com>
wrote:
>A SQL Server 2005 (developer edition) database contains both application
>data tables and ASP.NET membership tables and stored procedures and runs
>without error on computer A. When the database is detached, copied to
>computer B, and re-attached, the ASP.NET membership tables and stored
>procedures are gone. If you know the cause/cure for this issue, I would
>appreciate your help.
>Thanks,
>Keith
>

Thursday, February 9, 2012

ASP.net 2.0 Users (aspnet_Users table) create constraint problem

Hi all,
I am using ASP.NET 2.0 Membership system, which is driving me nuts. I
have my users, which I create correctly. Then I have a table "Models"
which contains models, created by different users. So I obviously need
to create a relationship between the users and the models. I wanted at
first to create a relationship like I'm used to do it, that is to add
an int field to my Model table that would be a reference on the primary
key of my Primary Table. However, as the primary key on the
aspnet_Users table is a uniqueidentifier, I decided to add a field
model_username instead. Then, I tried to create a relationship between
the aspnet_Users.UserName row and Model.model_username, but sql server
won't let me create it, I don't know why.
What is supposed to be the correct way to implement a constraint with
asp.net 2.0 users? I want to disallow the deletion of a user if he has
created a model.
Thank you,
ibiza
On 9 Mar 2006 11:41:46 -0800, ibiza wrote:

> However, as the primary key on the
> aspnet_Users table is a uniqueidentifier, I decided to add a field
> model_username instead.
Why? I assume you mean you added a field model_username to your new table
(not to the asp.net users table), right? If so, did you make sure it's the
same type and size as the aspnet username field (ie nvarchar(256))?
Also, primary keys must be unique, so if you can have mulitple models per
user, you need to have some kind of sequence number or other value in
addition to username to create your primary key.

> Then, I tried to create a relationship between
> the aspnet_Users.UserName row and Model.model_username, but sql server
> won't let me create it, I don't know why.
What is the error you are getting? It seems to work for me.

> What is supposed to be the correct way to implement a constraint with
> asp.net 2.0 users? I want to disallow the deletion of a user if he has
> created a model.
I'd create a uniqueidentifier in your table, and then create a foreign key
constraint on that. This is guaranteed unique, even if another user is
created with the same name.

ASP.net 2.0 Users (aspnet_Users table) create constraint problem

Hi all,
I am using ASP.NET 2.0 Membership system, which is driving me nuts. I
have my users, which I create correctly. Then I have a table "Models"
which contains models, created by different users. So I obviously need
to create a relationship between the users and the models. I wanted at
first to create a relationship like I'm used to do it, that is to add
an int field to my Model table that would be a reference on the primary
key of my Primary Table. However, as the primary key on the
aspnet_Users table is a uniqueidentifier, I decided to add a field
model_username instead. Then, I tried to create a relationship between
the aspnet_Users.UserName row and Model.model_username, but sql server
won't let me create it, I don't know why.
What is supposed to be the correct way to implement a constraint with
asp.net 2.0 users? I want to disallow the deletion of a user if he has
created a model.
Thank you,
ibizaOn 9 Mar 2006 11:41:46 -0800, ibiza wrote:
> However, as the primary key on the
> aspnet_Users table is a uniqueidentifier, I decided to add a field
> model_username instead.
Why? I assume you mean you added a field model_username to your new table
(not to the asp.net users table), right? If so, did you make sure it's the
same type and size as the aspnet username field (ie nvarchar(256))?
Also, primary keys must be unique, so if you can have mulitple models per
user, you need to have some kind of sequence number or other value in
addition to username to create your primary key.
> Then, I tried to create a relationship between
> the aspnet_Users.UserName row and Model.model_username, but sql server
> won't let me create it, I don't know why.
What is the error you are getting? It seems to work for me.
> What is supposed to be the correct way to implement a constraint with
> asp.net 2.0 users? I want to disallow the deletion of a user if he has
> created a model.
I'd create a uniqueidentifier in your table, and then create a foreign key
constraint on that. This is guaranteed unique, even if another user is
created with the same name.

ASP.net 2.0 Users (aspnet_Users table) create constraint problem

Hi all,
I am using ASP.NET 2.0 Membership system, which is driving me nuts. I
have my users, which I create correctly. Then I have a table "Models"
which contains models, created by different users. So I obviously need
to create a relationship between the users and the models. I wanted at
first to create a relationship like I'm used to do it, that is to add
an int field to my Model table that would be a reference on the primary
key of my Primary Table. However, as the primary key on the
aspnet_Users table is a uniqueidentifier, I decided to add a field
model_username instead. Then, I tried to create a relationship between
the aspnet_Users.UserName row and Model.model_username, but sql server
won't let me create it, I don't know why.
What is supposed to be the correct way to implement a constraint with
asp.net 2.0 users? I want to disallow the deletion of a user if he has
created a model.
Thank you,
ibizaOn 9 Mar 2006 11:41:46 -0800, ibiza wrote:

> However, as the primary key on the
> aspnet_Users table is a uniqueidentifier, I decided to add a field
> model_username instead.
Why? I assume you mean you added a field model_username to your new table
(not to the asp.net users table), right? If so, did you make sure it's the
same type and size as the aspnet username field (ie nvarchar(256))?
Also, primary keys must be unique, so if you can have mulitple models per
user, you need to have some kind of sequence number or other value in
addition to username to create your primary key.

> Then, I tried to create a relationship between
> the aspnet_Users.UserName row and Model.model_username, but sql server
> won't let me create it, I don't know why.
What is the error you are getting? It seems to work for me.

> What is supposed to be the correct way to implement a constraint with
> asp.net 2.0 users? I want to disallow the deletion of a user if he has
> created a model.
I'd create a uniqueidentifier in your table, and then create a foreign key
constraint on that. This is guaranteed unique, even if another user is
created with the same name.

ASP.NET / SQL 2k Membership prob

Almost have my custom membershipprovider finsihed, but have ran into a small snag.

Scenario:: 2 methods. CreateUser(blah blah) and ValidateUserName(string username). CreateUserWizard control calls CreateUser(blah blah) which in the start of the method calls ValidateUserName(string username). ValidateUserName runs astored procedure onSQL 2k to check and see if user exists in the db. Returns a bool true or false. If true, then everything works correctly and returns a message displaying that the user exists, please enter a different name.

Now the problem. If it returns false, meaning that the username doesnt exist and is available to use, it calls a stored procedure to create the record in the users db. This is where the problem lies. It does NOTHING but sit there waiting. But it never seems to time out. If I comment out the validating. It will add a record successfully.

Im wondering if it has something to do with calling 2stored procedures consecutivly??

::CODE TO FOLLOW::Heres the code.
------------

public override MembershipUser CreateUser(string username, stringpassword, stringemail, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
{
SqlConnection connect = null;
SqlCommand cmd = null;
MembershipUser newUser = null;

if (!ValidateUsername(username))
{
status = MembershipCreateStatus.DuplicateUserName;
return null;
}

try
{
connect = new SqlConnection(ConfigurationManager.ConnectionStrings[ConnString].ConnectionString);

cmd = new SqlCommand("createuser", connect);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add(new SqlParameter("@.UserName", username));
cmd.Parameters.Add(new SqlParameter("@.Pwd", password));
cmd.Parameters.Add(new SqlParameter("@.PwdQuestion", passwordQuestion));
cmd.Parameters.Add(new SqlParameter("@.PwdAnswer", passwordAnswer));
cmd.Parameters.Add(new SqlParameter("@.Email", email));
cmd.Parameters.Add(new SqlParameter("@.Comment", _Name));
cmd.Parameters.Add(new SqlParameter("@.IsApproved", MyMethods.BoolToInt(isApproved)));
cmd.Parameters.Add("@.IsLockedOut", SqlDbType.Bit).Value = 0;
cmd.Parameters.Add(new SqlParameter("@.CreationDate", DateTime.Now));
cmd.Parameters.Add(new SqlParameter("@.LastLoginDate", DateTime.Now));

connect.Open();
cmd.ExecuteNonQuery();

// Right now I am giving default values for DateTime
// in Membership constructor.
newUser = new MembershipUser(
_Name,
username, null, String.Empty, String.Empty,
String.Empty, true, false, DateTime.Now,
DateTime.Now, DateTime.Now, DateTime.Now,
DateTime.Now
);
status = MembershipCreateStatus.Success;
}
catch (Exception ex)
{
status = MembershipCreateStatus.ProviderError;
newUser = null;
throw ex;
}
finally
{
cmd.Dispose();
connect.Close();
}
return newUser;
}

private bool ValidateUsername(string userName)
{
SqlConnection conn = null;
SqlCommand cmd = null;
SqlDataReader reader = null;
bool IsValid = false;

try
{
conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings[ConnString].ConnectionString;

cmd = new SqlCommand("CheckUsername", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@.Username", userName));

conn.Open();
reader = cmd.ExecuteReader();
while (!reader.Read())
{
IsValid = true;
}
return IsValid;
}
catch (Exception ex)
{
throw ex;
}
finally
{
reader.Close();
cmd.Dispose();
conn.Close();
}
}|||

OK! NOT EVERYONE AT ONCE ! <big grin>

just kidding, anyways figured out the problem after pulling all but one last hair out.

The "while(!reader.Read())" was causing problems, just replaced it with "while(reader.HasRows)" and viola, it worked. Beats me.