Devise return incorect user ID? - ruby-on-rails-3

I get the error shown below on sign in (via Devise)
Oddly, Rails/Devise seems to be returning a user id of '1' even though there is no user in my users table with an id of '1'. This seems to happen kind of randomly, I can't figure out what the problem is.
Here's the latest error message.
ODBC::Error: S1000 (9001) [Microsoft][SQL Server Native Client 11.0][SQL Server]The log for database '[redacted]' is not available. Check the event log for related error messages. Resolve any errors and restart the database.: EXEC sp_executesql N'UPDATE [users] SET [last_sign_in_at] = ''2012-11-12T16:58:34.020'', [current_sign_in_at] = ''2012-11-13T08:44:33.586'', [sign_in_count] = 69, [updated_at] = ''2012-11-13T08:44:33.630'' WHERE [users].[id] = 1; SELECT ##ROWCOUNT AS AffectedRows'
Here's the request params:
{"utf8"=>"✓",
"authenticity_token"=>"[redacted]=",
"user"=>{"email"=>"jkramxx#xx.com",
"password"=>"[FILTERED]",
"remember_me"=>"0"},
"commit"=>"Sign in"}
There actually is no user in the db with an id of "1", and theres nothing wrong with the server. The user jkramxx#xx.com has id of 60. ( user id 1 was deleted from the db a while ago). I thought it might be something in the session cookie so i deleted that as well).
I've seen similar odd behavior in the console, where I have been able to log in, but when I examine current_user in the debugger it shows the user having an id of '1' even though when I examine the db directly (using SQL Server Mgmt Studio) the user has id of 34 and there is no user with id of 1. Sometimes this beahvior goes away when I restart the debugger. All very random.
Any suggestions?
(Ruby 1.9.3./Rails 3.2.8 SQL Server 10 using ruby-obdc gem)

Related

BMXAA0021E - User name and password combination are not valid. Try again

The following message appears in the SystemOut for Maximo, usually shortly after starting the server:
[16/08/16 12:30:05:468 BST] 00000037 SystemOut O 16 Aug 2016 12:30:05:468 [ERROR] [MAXDEVSVR] [CID-CRON-32] BMXAA0021E - User name and password combination are not valid. Try again.
psdi.util.MXAccessException: BMXAA0021E - User name and password combination are not valid. Try again.
at psdi.server.SimpleCronTask.start(SimpleCronTask.java:549)
at psdi.server.CronTaskManager.callCronMethod(CronTaskManager.java:1585)
at psdi.server.CronTaskManager.access$400(CronTaskManager.java:87)
at psdi.server.CronTaskManager$CronThread.run(CronTaskManager.java:1948)
How do I get rid of this?
For me, this turns out to be related to the scheduled reports cron-task. The "Run As" user may be inactive or blocked.
You can either deactivate the cron-task instance for each report, change the user, or use the following SQL to remove the instances:
delete from CRONTASKINSTANCE where exists(
select null from maxuser where userid = RUNASUSERID and status != 'ACTIVE'
);
Note that this query does not limit to the REPORTSCHEDULE cron-task so make sure you run a select beforehand to ensure that you aren't deleting something useful.

SSRS data driven subscription error

I have a data driven subscription with 71 parameters. Every-time I run my subscription I get 5 errors and 71 of 71 processed with 5 errors. But when I count my report only 66 reports have been created. I tried to check the log but couldn't find any errors other than at Microsoft.ReportingServices.Diagnostics.RevertImpersonationContext.Run(ContextBody callback)
at Microsoft.ReportingServices.Diagnostics.ExtensionClassFactory.CreateExtensionObject(Extension extConfig, Boolean typeOnly).
library!ReportServer_0-43!3b10!11/10/2015-11:46:20:: i INFO: Call to GetSystemPropertiesAction().
library!ReportServer_0-43!411c!11/10/2015-11:46:20:: e ERROR: Throwing Microsoft.ReportingServices.Diagnostics.Utilities.LogonFailedException: Logon attempt for user 'user' failed., Microsoft.ReportingServices.Diagnostics.Utilities.LogonFailedException: Log on failed. Ensure the user name and password are correct. ---> System.ComponentModel.Win32Exception: The user name or password is incorrect
at Microsoft.ReportingServices.Diagnostics.Utilities.LoginUtil.Login(String userName, IntPtr ptrPwd, String domain)
at Microsoft.ReportingServices.Diagnostics.Utilities.LoginUtil.Login(String userName, SecureStringWrapper userPwd, String domain)
at Microsoft.ReportingServices.Diagnostics.ImpersonationContext..ctor(String userName, SecureStringWrapper password, String domain)
--- End of inner exception stack trace ---;
Am I missing something,not reading the log properly? any help is appreciated. Thanks in advance!
To identify which logs are failing, you can view the report server's execution logs:
Use ReportServer
select * from ExecutionLog order by TimeStart DESC
The 'ReportID' field can be looked up in the reportserver's 'catalog' table. I find that having an SSRS report set up that queries this is invaluable.
Once you identify the reports that are failing (via the above queries) then you can try running them manually, to see if they work. If they do work, then set up a subscription for just those reports, and see if they work when run as a subscription.
If you've never had a problem with these before, my bet is that the datasources use pass-through authentication, which works when logged in, but not when run automatically.
Let us know how you get on!

Database Mail not sending

I'm trying to send email using the DatabaseMail on SQL Server 2008; I can see my emails sitting in the msdb.dbo.sysmail_unsentitems
But they just sit there and I get no error messages.
I've checked and I have rights to use the DatabaseMail by using the following:
EXEC msdb.sys.sp_helprolemember 'DatabaseMailUserRole';
And I tried running
EXEC msdb.dbo.sysmail_help_queue_sp #queue_type = 'mail';
which shows the length as the number of emails I've tried to send, but the Status is showing as Inactive.
Am I missing something else?

Box API with new omniauth-box gem not redirecting to my app (ERROR Errno::ECONNRESET: Connection reset by peer)

I created a gem to work with Box API V2 (https://github.com/youpdidou/omniauth-box/). I tested it in development. The authentication is created as needed and recorded in DB, but there is an error in the redirect to my page at the end of the process (cf. log below).
My app works fine with other providers (I have Twitter and Yammer, using the omniauth-twitter, and omniauth-yammer gem), so it seems the error could come something I am missing in my Gem (something related to the refresh token?), or maybe it is related to the fact The Box authentication process has 2 steps (1 for credentials, 1 to authorize access to files - cf. http://developers.box.com/oauth/)...
What am I missing here? How to debug this, and what should I look at?
(box) Callback phase initiated.
Started GET "/auth/box/callback?state=7d550f7c0d367d4af73ca3a1d82985c78730126887e3e813&code=fV19In0Elnq1GNX61t32N1h8anezbTiH" for 127.0.0.1 at 2013-01-30 00:28:18 -0800
Processing by AuthenticationsController#create as HTML
Parameters: {"state"=>"7d550f7c0d367d4af73ca3a1d82985c78730126887e3e813", "code"=>"fV19In0Elnq1GNX61t32N1h8anezbTiH", "provider"=>"box"}
User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
Authentication Load (0.5ms) SELECT `authentications`.* FROM `authentications` WHERE `authentications`.`user_id` = 1 AND `authentications`.`provider` = 'box' AND `authentications`.`uid` = '288560' LIMIT 1
(0.1ms) BEGIN
SQL (0.3ms) INSERT INTO `authentications` (`created_at`, `oauth_secret`, `oauth_token`, `provider`, `uid`, `updated_at`, `user_id`) VALUES ('2013-01-30 08:28:19', NULL, NULL, 'box', '288560', '2013-01-30 08:28:19', 1)
(1.5ms) COMMIT
(0.1ms) BEGIN
(0.4ms) UPDATE `authentications` SET `oauth_token` = 'cZga3uA89eslNAURbJlZaySukIs9IxTF', `updated_at` = '2013-01-30 08:28:19' WHERE `authentications`.`id` = 26
(0.5ms) COMMIT
Redirected to http://localhost:3000/services
Completed 302 Found in 14ms (ActiveRecord: 3.7ms)
[2013-01-30 00:28:19] ERROR Errno::ECONNRESET: Connection reset by peer
/Users/alex/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:80:in `eof?'
/Users/alex/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:80:in `run'
/Users/alex/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
This isn't related to box I think but rails itself, you might want to look at:
ERROR Errno::ECONNRESET: Connection reset by peer
as this person seems to have near enough the exact same error as you.
EDITED to include answer:
quoted from #Matt Smith
My quick guess is this looks like you have a problem with your sessions and protect_from_forgery is kicking in.
I had a similar problem and smashed my head against the wall for a few days, it turned out to be I was assigning an entire object to a session object instead of just the id. A quick note, non-GET requests are the ones that trigger the protect_from_forgery.
I had a similar problem in a non-rails app. In my case I was doing some ajax requests on client and redirected to the box authentication page afterwards, without waiting for the server to complete the requests.
Using a promise and redirecting after the request is done fixed the issue. Something like:
$.ajax(my_url, {dataType: "json"}).then(function(data){window.location.replace(auth_url)};
Hope you find some inspiration here.

Would like help with LOGON Trigger

I've created a logon trigger in MS SQL that needs to check dm_exec_sessions for a login. This login is the user listed in the connection string and has owner right to the database. If the login is verified, I need it to update a specific table and send an email.
So far I've done just the following piece and it disabled my web site. The error I get is: "Logon failed for login 'dev' due to trigger execution. Changed database context to 'mydatabase'. Changed language setting to us_english."
Any idea what I did wrong? Thanks,
Risho
CREATE TRIGGER TDY_Assets_Notification
ON ALL SERVER WITH EXECUTE AS 'dev'
FOR LOGON
AS
BEGIN
IF ORIGINAL_LOGIN()='dev' AND
(SELECT COUNT(*) FROM sys.dm_exec_sessions
WHERE is_user_process = 1 AND
original_login_name = 'dev') > 1
UPDATE Assets_TDY
SET Suspense = 1, Warning = 1
WHERE (Date_Returned IS NULL) AND (GETDATE() >= DATEADD(day, 3, Date_Return))
END
Try connecting with the Dedicated Administrator Connection. That will give you an opportunity to disable the faulty logon trigger.
DISABLE TRIGGER [TDY_Assets_Notification] ON ALL SERVER