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
Related
I am creating web app in Laravel which connects to MSSQL DB (using PDO) and i'm stuck with a issue when running query (UPDATE in my case)
update dba.[vl_zahlavi] set [xcmd] = ' AFTERCOMMIT', [vl_zahlavi].[ts] = '2023-01-10 14:16:06.505' where [doklad] = '23VLTU0100000001'
which raises error with severity 0 within update trigger (used for sending progress bar information to client). Trigger is created within information system, so I'm not able to disable this functionality.
select #progress_count = convert(int/*BY*/,#akt_pocet), #progress_current = 0, #progress_dt_o_skl_o_skl_gen_poh_prub = DateAdd(ms, -1000, GetDate())
select #progress_arg = '#SQL_PROGRESS=O_SKL,O_SKL_GEN_POH_PRUB,' + convert(varchar(255)/*BY*/, ##nestlevel) + ',OPEN,' + convert(varchar(255)/*BY*/, #progress_count) + ';'
RAISERROR ('%s', 0, 1, #progress_arg) WITH NOWAIT
Problem is, that PHP client send abort and transaction is automatically rolled back. When I comment this section of code (or change severity to 16), everything works as expected. Bellow is printscreen from SQL server profiler.
printscreen
Is PDO able to catch user error messages?
Thank you in advance.
I have tried to change DB sets and PDO options, but without success.
I'm also new to DevOps, but let me see if I can explain my situation, also if anyone has any advice on doing post deployment scripts and can share their experiences I will be most grateful.
I use SQL Source control from Redgate, Git and Azure DevOps. I have managed to get the build and deployment working perfectly. Additionally we would like to make some data changes so we have additional (Data Change) scripts we wish to run. Linking these tables as static data is not an option as we would end up having most tables linked and end up with extremely timeous build and deploy times.
The script inserts data to a table, thereby triggering the insert trigger which calls a procedure to write to an audit table. The actual error from the deployment log is:
Task : DbUp Migration
2021-01-25T12:52:17.2629353Z Description : Runs SQL Server change scripts, and only those which have not been run already.
2021-01-25T12:52:17.2629405Z Version : 2.1.4
2021-01-25T12:52:17.2629671Z Author : Johan Classon
2021-01-25T12:52:17.2629721Z Help : [More Information](https://github.com/johanclasson/vso-agent-tasks)
2021-01-25T12:52:17.2629775Z ==============================================================================
2021-01-25T12:52:19.6610608Z Beginning database upgrade
2021-01-25T12:52:19.6689401Z Checking whether journal table exists..
2021-01-25T12:52:19.6728756Z Journal table does not exist
2021-01-25T12:52:19.7775348Z Executing Database Server script '001 - EX27605 - rdl.sql'
2021-01-25T12:52:19.7908913Z Checking whether journal table exists..
2021-01-25T12:52:19.7929056Z Creating the [dbo].[_SchemaVersions] table
2021-01-25T12:52:19.8077238Z The [dbo].[_SchemaVersions] table has been created
2021-01-25T12:52:20.2264323Z ifExists - rdl_Rule_Definition_Lookup - rdl_Code = "9900226e"
2021-01-25T12:52:20.2277308Z insert - rdl_Rule_Definition_Lookup - rdl_Code = "9900226e"
2021-01-25T12:52:20.2805780Z SQL exception has occured in script: '001 - EX27605 - rdl.sql'
2021-01-25T12:52:20.2942912Z ##[error]Script block number: 0; Block line 74; Message: Trig_After_Ins_Upd_Del_rdl_Rule_Definition_Lookup
2021-01-25T12:52:20.4528752Z ##[error]System.Data.SqlClient.SqlException (0x80131904): p_dte_Audit_Backend: (Line: 108) [dte_admin]
So the 1st error refers to line 74 of the trigger, if I read this correctly which is a commit on a procedure call to write to the audit table, line 108 of my procedure sets the userID:
DECLARE #user VARCHAR(40)
SET #user =
CASE
WHEN suser_sname() = 'NT SERVICE\SQLAgent$'+##servicename THEN 'dte_admin'
WHEN suser_sname() = 'NT SERVICE\SQLSERVERAGENT' THEN 'dte_admin'
ELSE suser_sname()
END
--###############
select #udt_Audit = udt_Audit
from udt_User_Detail (nolock)
where udt_User_Id = #user--suser_sname()
--select #udt_Audit = udt_Audit from udt_User_Detail
--where udt_User_Id = suser_sname()
if ##rowcount = 0
begin
declare #udt_User_Id varchar(30)
set #udt_User_Id = suser_sname()
The last line being line 108.
Important to note that dte_admin is a login on the SQL Server, it is a sysadmin account and mapped to the database, the dte_admin user is also a user at database level and exists as a user in my user table udt_user_detail.
During the build and deployment I am using variables and they are set to dte_admin username and password.
My question is then, why does this fail with this user?
Deployment Pipeline result
I am getting an authentication required message on google chrome when logging into oracle apex admin.
screenshot of error:
I'm assuming you're using the embedded PL/SQL Gateway and the XDB Protocol Server, correct? If so, please ensure:
You have run #apex_epg_config.sql
You have unlocked the ANONYMOUS database user
https://docs.oracle.com/database/apex-5.1/HTMIG/configuring-embedded-PL-SQL-gateway.htm#HTMIG29205
Why this happens? Because the ANONYMOUS account is locked and/or expired.
Log in to main container database (not PDB)
Run the following query to determine status:
select account_status from dba_users where username = 'ANONYMOUS';
If account_status is expired, run the following:
alter user ANONYMOUS identified by anonymous;
alter user ANONYMOUS account unlock;
If account_status is locked, run the following:
alter user ANONYMOUS account unlock;
When using IE instead of Chrome the login message refers to XDB. It seems like a problem with anonymous connection. This thread gives a solution for enabling this anonymous access. Though I think this is not probably a good solution, I don't have enough knowledge to solve it in a better way. In case the link is broken, I'm pasting the solution here. It worked for me, and I've seen this solution in a few more places so I maybe this is quite common...
(with CONN sys/password AS SYSDBA)
SET SERVEROUTPUT ON
DECLARE
l_configxml XMLTYPE;
l_value VARCHAR2(5) := 'true'; -- (true/false)
BEGIN
l_configxml := DBMS_XDB.cfg_get();
IF l_configxml.existsNode('/xdbconfig/sysconfig/protocolconfig/httpconfig/allow-repository-anonymous-access') = 0 THEN
-- Add missing element.
SELECT insertChildXML
(
l_configxml,
'/xdbconfig/sysconfig/protocolconfig/httpconfig',
'allow-repository-anonymous-access',
XMLType('<allow-repository-anonymous-access xmlns="http://xmlns.oracle.com/xdb/xdbconfig.xsd">' ||
l_value ||
'</allow-repository-anonymous-access>'),
'xmlns="http://xmlns.oracle.com/xdb/xdbconfig.xsd"'
)
INTO l_configxml
FROM dual;
DBMS_OUTPUT.put_line('Element inserted.');
ELSE
-- Update existing element.
SELECT updateXML
(
DBMS_XDB.cfg_get(),
'/xdbconfig/sysconfig/protocolconfig/httpconfig/allow-repository-anonymous-access/text()',
l_value,
'xmlns="http://xmlns.oracle.com/xdb/xdbconfig.xsd"'
)
INTO l_configxml
FROM dual;
DBMS_OUTPUT.put_line('Element updated.');
END IF;
DBMS_XDB.cfg_update(l_configxml);
DBMS_XDB.cfg_refresh;
END;
/
I tried to execute a stored procedure. But I this error below, at every stance of execution:
Msg 18456, Level 14, State 1, Line 3 Login failed for user 'NT
AUTHORITY\ANONYMOUS LOGON'.
Thank you.
This is what I try to execute:
USE [Artikelen]
GO
DECLARE #return_value int
EXEC #return_value = [dbo].[BerekenSKU]
#loc = N'AM',
#lev = N'3436',
#reset = true
SELECT 'Return Value' = #return_value
GO
I am using Microsoft SQL 2014
Error shows that there is credential issue. Please check this link.
This message indicates that you are attempting to access the linked
server by using Windows NT authentication to impersonate the client
connecting. Refer Link
Look at the stored procedure in question. The login is failing at the
linked server because whoever is calling it doesn't have mapped
credentials set up.
Refer this links:
sqlcmd: Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'
http://www.sqlservercentral.com/Forums/Topic548200-146-1.aspx
http://www.sqlservercentral.com/Forums/Topic1523177-1550-1.aspx
http://www.sqlservercentral.com/Forums/Topic246883-110-1.aspx
http://www.sqlservercentral.com/Forums/Topic246883-110-1.aspx
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)