By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,378 Members | 1,455 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,378 IT Pros & Developers. It's quick & easy.

'Failed to enable constraints' Error on TableAdapter.Fill

abehm
P: 35
Hey all,
I'm getting this error only when I have two similar entries in an login_audit table where the only difference is the actionhost and date. The query works fine in sqlserver. just not in the dataset.

What can I do to solve this problem?

The table structure is:
Expand|Select|Wrap|Line Numbers
  1. userID(Guid)
  2. username (nvarchar(50))
  3. firstname (nvarchar(50))
  4. lastname(nvarchar(50))
  5. email(nvarchar(MAX))
  6. isAdmin bit
  7. Action (nvarchar(20))
  8. ActionHost(nvarchar(30))
  9. Date datetime
  10.  
The entries:
Expand|Select|Wrap|Line Numbers
  1. 860B3D0F-D166-4388-82C0-EA5D77C2E231
  2. newuser
  3. New
  4. User
  5. new.user@company.com
  6. 1
  7. Logged In    
  8. LOCALMACHINE
  9. Apr  3 2008  3:24PM
  10.  
  11. 860B3D0F-D166-4388-82C0-EA5D77C2E231
  12. newuser
  13. New
  14. User
  15. new.user@company.com
  16. 1
  17. Logged In
  18. SERVERNAME
  19. Apr  3 2008  3:23PM
  20.  
And this is the stored procedure:

Expand|Select|Wrap|Line Numbers
  1. ALTER PROCEDURE [Security].[User_SelectDepartmentMembersLoginInfo]
  2.     @UserID uniqueidentifier
  3. AS
  4. BEGIN
  5. SELECT DISTINCT [Security].[User].UserID, Username, FirstName, LastName, Email, IsSysAdmin, [Action], ActionHost, CONVERT(varchar(MAX),MAX(Date)) AS LastLoggedIn
  6. FROM [Security].[User] LEFT OUTER JOIN Audit.[Login] ON [Security].[User].UserID = Audit.[Login].UserID LEFT OUTER JOIN [Security].DepartmentMembers ON [Security].[User].UserID = DepartmentMembers.UserID
  7.     WHERE ((@UserID IN (SELECT UserID FROM [Security].[User] WHERE IsSysAdmin = 'True'))
  8.     OR (DepartmentMembers.DepartmentID = (SELECT DepartmentID FROM [Security].DepartmentMembers WHERE UserID = @UserID AND IsDeptAdmin = 'True'))
  9.     AND (([Action] = 'Logged In') OR ([Action] IS NULL)))
  10.     GROUP BY [Security].[User].UserID, Username, FirstName, LastName, Email, IsSysAdmin, [Action], ActionHost
  11.     ORDER BY LastLoggedIn DESC, Username
  12.  
  13. END
  14.  
Apr 3 '08 #1
Share this Question
Share on Google+
2 Replies


ck9663
Expert 2.5K+
P: 2,878
Hey all,
I'm getting this error only when I have two similar entries in an login_audit table where the only difference is the actionhost and date. The query works fine in sqlserver. just not in the dataset.

What can I do to solve this problem?

The table structure is:
Expand|Select|Wrap|Line Numbers
  1. userID(Guid)
  2. username (nvarchar(50))
  3. firstname (nvarchar(50))
  4. lastname(nvarchar(50))
  5. email(nvarchar(MAX))
  6. isAdmin bit
  7. Action (nvarchar(20))
  8. ActionHost(nvarchar(30))
  9. Date datetime
  10.  
The entries:
Expand|Select|Wrap|Line Numbers
  1. 860B3D0F-D166-4388-82C0-EA5D77C2E231
  2. newuser
  3. New
  4. User
  5. new.user@company.com
  6. 1
  7. Logged In    
  8. LOCALMACHINE
  9. Apr  3 2008  3:24PM
  10.  
  11. 860B3D0F-D166-4388-82C0-EA5D77C2E231
  12. newuser
  13. New
  14. User
  15. new.user@company.com
  16. 1
  17. Logged In
  18. SERVERNAME
  19. Apr  3 2008  3:23PM
  20.  
And this is the stored procedure:

Expand|Select|Wrap|Line Numbers
  1. ALTER PROCEDURE [Security].[User_SelectDepartmentMembersLoginInfo]
  2.     @UserID uniqueidentifier
  3. AS
  4. BEGIN
  5. SELECT DISTINCT [Security].[User].UserID, Username, FirstName, LastName, Email, IsSysAdmin, [Action], ActionHost, CONVERT(varchar(MAX),MAX(Date)) AS LastLoggedIn
  6. FROM [Security].[User] LEFT OUTER JOIN Audit.[Login] ON [Security].[User].UserID = Audit.[Login].UserID LEFT OUTER JOIN [Security].DepartmentMembers ON [Security].[User].UserID = DepartmentMembers.UserID
  7.     WHERE ((@UserID IN (SELECT UserID FROM [Security].[User] WHERE IsSysAdmin = 'True'))
  8.     OR (DepartmentMembers.DepartmentID = (SELECT DepartmentID FROM [Security].DepartmentMembers WHERE UserID = @UserID AND IsDeptAdmin = 'True'))
  9.     AND (([Action] = 'Logged In') OR ([Action] IS NULL)))
  10.     GROUP BY [Security].[User].UserID, Username, FirstName, LastName, Email, IsSysAdmin, [Action], ActionHost
  11.     ORDER BY LastLoggedIn DESC, Username
  12.  
  13. END
  14.  

Check your table. I think you have a PRIMARY KEY constraint that prevents you from inserting those duplicate rows.

-- CK
Apr 3 '08 #2

abehm
P: 35
Check your table. I think you have a PRIMARY KEY constraint that prevents you from inserting those duplicate rows.

-- CK

lol.

I just saw that too!
I was just about to post to disregard that.
my bad.
Apr 3 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.