Cannot use the special principal 'sa' - sql

When I try to run the command:
EXEC master..sp_addsrvrolemember #loginame = N'sa', #rolename = N'serveradmin'
GO
I get the error:
Msg 15405, Level 11, State 1, Procedure sp_addsrvrolemember, Line 45
Cannot use the special principal 'sa'.
Ideas/suggestions welcome.

'sa' is a reserved login for the sysadmin; it's already a member of the sysadmin group, which trumps all other groups. You don't need to add it to any roles, so why are you trying to do that?

Related

Querying Active Directory with T-SQL

Have tried:
EXEC master.dbo.sp_addlinkedserver
#server = N'ADSI',
#srvproduct=N'Active Directory Services',
#provider=N'ADsDSOObject',
#datasrc=N'server_name.your_domain.com'
EXEC master.dbo.sp_addlinkedsrvlogin
#rmtsrvname=N'ADSI',
#useself=N'False',
#locallogin=NULL,
#rmtuser=N'your_domain\domain_user',
#rmtpassword='********'
SELECT *
FROM OPENQUERY (ADSI, 'SELECT *
FROM ''LDAP://DC=your_domain,DC=com''')
Getting this error:
Msg 7321, Level 16, State 2, Line 1
An error occurred while preparing the query "SELECT * FROM 'LDAP://DC=your_domain,DC=com'" for execution against OLE DB provider "ADsDSOObject" for linked server "ADSI".
I have already confirmed mine and the SQL Server Service domain accounts have read access to AD, and that the "Allow inprocess" is enabled on the ADsDSOObject provider is selected.
Any thoughts would be appreciated.
Every example I could find had: LDAP://DC=your_domain,DC=com as syntax. Well for our server (and maybe other's) it is: LDAP://DC=your_domain,DC=internal
As suggested by someone, I used the Softerra LDAP browser (free) and opened the server, clicked on the top node and found distinguished name entry listed as: DC=your_domain,DC=internal
Once I made that change, I could see the AD data.

Execute stored procedure, but access denied

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

SQL Server Error 208: Invalid object name 'Utils.dbo.ChangeLogging_DDLCommands'

When trying to change the user account to link with the NewMary login:
EXEC sp_change_users_login 'Update_One', 'Mary', 'NewMary'
go
I get the error 208:
Msg 208, Level 16, State 1, Procedure ChangeLogging_LogDDLCommands, Line 147
Invalid object name 'Utils.dbo.ChangeLogging_DDLCommands'.
I don't find any relevant information on ChangeLogging_DDLCommands, and I'm lost at how I do have to proceed from there.
Sounds like you have some kind of custom trigger, which is missing this object.
In SSMS:
Check server triggers under "Server Objects" > "Triggers"
Check individual database DDL triggers under "Programmability" -> "Database triggers"

how to execute Grant and Revoke command using JDBC connection

I don't know whether I am able to execute the Grant,Revoke query using Jdbc connection.
here is the Code kindly suggest me where am I leading wrong?
query="create user "+username+" identified by "+userpass;
query1="Grant Connect,Resource,DBA to"+username;
query2="Grant Create SESSION Grant ANY PRIVILEGE to"+username;
query3="Grant UNLIMITED TABLESPACE to"+username;
query4="GRANT Select,Update,Insert on"+TableName+"to"+username;
System.out.println(query);
System.out.println(query2);
System.out.println(query3);
st=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
b=st.execute(query);
b1=st.execute(query1);
b2=st.execute(query2);
b3=st.execute(query3);
System.out.println(query1+query2+query3);
I am getting the following error :
ORA-00990: missing or invalid privilege
The entire connection and Code is fine .
try to write when you are creating user
query = "create user '" + username + "'#'localhost' identified by " + userpass;
it can help if you are using a local server

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