SQL server - job calling procedure and procedure difference - sql-server

I'm trying to create table from view from remote server (calling procedure UPDATE_PROC), like this:
SELECT *
INTO table
FROM [remote_server\database].DATABASE.dbo.view
And it works perfectly.
Problem is, when I try to create a new job, which is calling the previously worked stored procedure UPDATE_PROC
exec UPDATE_PROC
It doesn't work and reports:
Executed as user: NT AUTHORITY\SYSTEM. The OLE DB provider "SQLNCLI10" for linked server "remote_server\database" does not contain the table ""DATABASE"."dbo"."view"". The table either does not exist or the current user does not have permissions on that table. [SQLSTATE 42000] (Error 7314). The step failed
So it seems to be same, but it isn't. What I'm doing wrong?
UPDATE:
Remote server is SQL Server 2005, job is on SQL Server 2008
I'm logged as sa user. Procedure is working always, job calling stored procedure never
Job isn't run as sa user, but I don't know which user and where should be defined to execute the job propery....

It seems to me that's a security issue. User under which the job is running doesn't have permissions to access table on the remote server.

Related

How do I automatically fire a (remote) stored procedure in SQL Server when connecting to a remote server?

The specific issue is that I want a SQL Server to connect to an Oracle database and the Oracle database has a Virtual Private Database configured. I need to execute a static stored procedure to enable the VPD to see data. How can I configure SQL Server to fire a stored procedure upon connecting to a remote database? I figure if I can fire a local stored procedure, I can put the remote stored procedure call inside of that. The key is, I need the SQL Server to fire this as soon as it is done connecting to the remote database and before it tries to pass any other queries to it. I'm trying to avoid making the applications do it explicitly.
SQL Server does not offer a solution to my problem.
However, you can setup the service account to have a logon trigger to execute what is needed.
Create Trigger My_User.Logon_Trigger_Name
AFTER LOGON
ON SCHEMA
WHEN (USER = 'MY_USER')
BEGIN
--Do Stuff Here.
NULL;
EXCEPTION
WHEN OTHERS THEN
NULL; --Consume errors so you can still log on.
END;

OLE DB provider "OraOLEDB.Oracle" for linked server returned message "ORA-06576: not a valid function or procedure name"

I have setup a linked server from SQL Server to a Oracle database. Connection has been tested as successfully. I use the following to query a table from SQL Server and it successfully returned me the result set:
EXEC ('select * from tablename') AT [linkedservername]
I ran the following from the Oracle database, it(stored procedure) works:
EXEC schemaname.storedprocedurename
However, when I ran this from SQL server, it returned me the error message ORA-00900: invalid SQL statement
EXEC('call schemaname.storedprocedurename') AT [linkedservername]
Anyone has any idea what might be the cause?
Matt,
You are missing the () after the procedure name.
EXEC('call schemaname.storedprocedurename()') AT [linkedservername]
Also, make sure of the following
The account being used to link the servers has access to the stored procedure (schema)
Sometimes you may need to omit the schema name and just do the 'Call SPName()'

Change password in ORACLE from SQL Server via linked server

I have an Oracle database connected to a SQL Server. The connection works correctly, but unfortunately, I don't know the password used for that connection. Now I need to change the password in Oracle.
Is it a good idea to run something like
SELECT * FROM OPENQUERY([oracle], '
ALTER USER OracleUser IDENTIFIED BY pswd;
SELECT 1 FROM DUAl')
Or maybe, is there another solution?
UPD
My query ends with error
The OLE DB provider "OraOLEDB.Oracle" for linked server "oracle" indicates that either the object has no columns or the current user does not have permissions on that object
Correct syntax for changing password in Oracle from SQL Server via linked server is
EXEC ('ALTER USER OracleUser IDENTIFIED BY new_password REPLACE old_password') AT [oracle]

Unable to call stored procedure from linked server

I am facing a strange issue. I have a linked server on ServerB for ServerA
Now, when I am calling a stored procedure from ServerB like
EXEC [ServerA].[Db].[dbo].[SpName] #Param1 #param2
I am getting error that
The EXECUTE permission was denied on the object 'SpName', database 'Db', schema 'dbo'.
But now when I am executing below query it is returning me result:
SELECT *
FROM [ServerA].[Db].[dbo].[tblName]
I don't know that why I am not able to execute stored procedure from ServerB. I am Db_Owner on both the server.
Screenshot of Linked server security
Linked server catalog
If a linked server query fails, the things to check are (in rough order of probability):
Try logging in locally on the linked server to test access directly. If you have no local access, obviously you won't have it through the link either.
Verify the correct credentials as used when accessing the linked server, and not another user you're not expecting. You can check this with EXEC ('SELECT USER_NAME(), SUSER_NAME()') AT [Server]; if the user name is not what you're expecting, check your linked server definition for the correct login mappings. If you can't access the server at all (any query fails), you have other problems (like Kerberos authentication issues if you're using integrated authentication).
Perform a sanity check that you're accessing the correct server with EXEC ('SELECT ##SERVERNAME') AT [Server]. The network name of a linked server can be changed using sp_setnetname, so the name you use to a access the server isn't necessarily the machine name.
If all else fails, dropping and recreating the linked server definition is always an option, but obviously this could disrupt production work.

Sql server Agent job is failing with a login error

SQL Server 2008 in SSMS
I'm getting this error when running a job I just created using SQL Server Agent:
Executed as user: DNA\circsrv. Database 'DN' does not exist. Make sure that the name is entered correctly. [SQLSTATE 08004] (Error 911). The step failed.
DNA is the name of a network domain, and circsrv is a valid user in that domain.
The Process for the Sql Server Agent is started by user DNA\circsrv but the job itself is owned by a different user, dn-atcore1\syncronexadmin
#owner_login_name=N'DN-ATCORE1\syncronexadmin'
(dn-atcore1 is the name of the system, and syncronexadmin is a local user on the box)
This seems like it should be simple, but I'm just not getting it.
Any ideas? Thanks for any help.
Barb
Do you have a database called 'DN'? The error states that the database does not exist. When you created the job did you set the database?
Does the database exist?
Run this code to check.
-- main database
use master;
go
-- does the db exist?
select *
from sys.sysdatabases
where name like 'DN%'
go
If it does not exist, you have bigger issues here!
Time to find a backup to restore from ...

Resources