MSSQL Agent Task Failing - Stored Procedure












0















I have a stored procedure that is giving me some issues as an Agent Job



When running the task, I get the following error:



Executed as user: SQLUserName. Access to the remote server is denied because the current security context is not trusted. [SQLSTATE 42000] (Error 15274). The step failed.



The Task has 1 step and that step is just "EXEC dbo.Procdure_Name" and the "Run as" is blank (i'm unable to specify anything here). I have put in "Advanced", "Run as user" as SQLUserName.



When I remove this, I get the error:



Executed as user: domainservename$. Login failed for user 'domainservername$'. [SQLSTATE 28000] (Error 18456).  The step failed.


This is running a command on a linked server. When I remove that command it works.



The linked server is set to logon to "be made using the login's current security context" and testing the link server works fine.



If I log into SMSS as SQLUserName and run the procedure manually it works fine.



Would appreciate any suggestions.










share|improve this question























  • What is the owner of the job set to?

    – George.Palacios
    20 hours ago
















0















I have a stored procedure that is giving me some issues as an Agent Job



When running the task, I get the following error:



Executed as user: SQLUserName. Access to the remote server is denied because the current security context is not trusted. [SQLSTATE 42000] (Error 15274). The step failed.



The Task has 1 step and that step is just "EXEC dbo.Procdure_Name" and the "Run as" is blank (i'm unable to specify anything here). I have put in "Advanced", "Run as user" as SQLUserName.



When I remove this, I get the error:



Executed as user: domainservename$. Login failed for user 'domainservername$'. [SQLSTATE 28000] (Error 18456).  The step failed.


This is running a command on a linked server. When I remove that command it works.



The linked server is set to logon to "be made using the login's current security context" and testing the link server works fine.



If I log into SMSS as SQLUserName and run the procedure manually it works fine.



Would appreciate any suggestions.










share|improve this question























  • What is the owner of the job set to?

    – George.Palacios
    20 hours ago














0












0








0








I have a stored procedure that is giving me some issues as an Agent Job



When running the task, I get the following error:



Executed as user: SQLUserName. Access to the remote server is denied because the current security context is not trusted. [SQLSTATE 42000] (Error 15274). The step failed.



The Task has 1 step and that step is just "EXEC dbo.Procdure_Name" and the "Run as" is blank (i'm unable to specify anything here). I have put in "Advanced", "Run as user" as SQLUserName.



When I remove this, I get the error:



Executed as user: domainservename$. Login failed for user 'domainservername$'. [SQLSTATE 28000] (Error 18456).  The step failed.


This is running a command on a linked server. When I remove that command it works.



The linked server is set to logon to "be made using the login's current security context" and testing the link server works fine.



If I log into SMSS as SQLUserName and run the procedure manually it works fine.



Would appreciate any suggestions.










share|improve this question














I have a stored procedure that is giving me some issues as an Agent Job



When running the task, I get the following error:



Executed as user: SQLUserName. Access to the remote server is denied because the current security context is not trusted. [SQLSTATE 42000] (Error 15274). The step failed.



The Task has 1 step and that step is just "EXEC dbo.Procdure_Name" and the "Run as" is blank (i'm unable to specify anything here). I have put in "Advanced", "Run as user" as SQLUserName.



When I remove this, I get the error:



Executed as user: domainservename$. Login failed for user 'domainservername$'. [SQLSTATE 28000] (Error 18456).  The step failed.


This is running a command on a linked server. When I remove that command it works.



The linked server is set to logon to "be made using the login's current security context" and testing the link server works fine.



If I log into SMSS as SQLUserName and run the procedure manually it works fine.



Would appreciate any suggestions.







sql-server






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 22 hours ago









Stephen PefanisStephen Pefanis

342




342













  • What is the owner of the job set to?

    – George.Palacios
    20 hours ago



















  • What is the owner of the job set to?

    – George.Palacios
    20 hours ago

















What is the owner of the job set to?

– George.Palacios
20 hours ago





What is the owner of the job set to?

– George.Palacios
20 hours ago










1 Answer
1






active

oldest

votes


















0















I have put in "Advanced", "Run as user" as SQLUserName




This is not the option to use in your case.



Using this option you can specify the user, not login, to run your sp. However, when you connect to linked server, it's not a database user, but server login that is used, it's "login's current security context" that will be used.



So in your case all depends on the job's owner. If it's sysadmin, the job is executed under Windows account of your SQL Server Agent, and if it's not sysadmin, the job is executing using job's owner's login.



From your error it seems that your job's owner is sysadmin, as domainservename$ is used. This is because your Agent is running under Local System or Network Service that when going on the network use your pc's account, domainPCname$.



To fix you problem you can either change job owner to some login that has access to linked server or change SQL Server Agent's service account to domain account that should be mapped on linked server.






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "182"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f227451%2fmssql-agent-task-failing-stored-procedure%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0















    I have put in "Advanced", "Run as user" as SQLUserName




    This is not the option to use in your case.



    Using this option you can specify the user, not login, to run your sp. However, when you connect to linked server, it's not a database user, but server login that is used, it's "login's current security context" that will be used.



    So in your case all depends on the job's owner. If it's sysadmin, the job is executed under Windows account of your SQL Server Agent, and if it's not sysadmin, the job is executing using job's owner's login.



    From your error it seems that your job's owner is sysadmin, as domainservename$ is used. This is because your Agent is running under Local System or Network Service that when going on the network use your pc's account, domainPCname$.



    To fix you problem you can either change job owner to some login that has access to linked server or change SQL Server Agent's service account to domain account that should be mapped on linked server.






    share|improve this answer




























      0















      I have put in "Advanced", "Run as user" as SQLUserName




      This is not the option to use in your case.



      Using this option you can specify the user, not login, to run your sp. However, when you connect to linked server, it's not a database user, but server login that is used, it's "login's current security context" that will be used.



      So in your case all depends on the job's owner. If it's sysadmin, the job is executed under Windows account of your SQL Server Agent, and if it's not sysadmin, the job is executing using job's owner's login.



      From your error it seems that your job's owner is sysadmin, as domainservename$ is used. This is because your Agent is running under Local System or Network Service that when going on the network use your pc's account, domainPCname$.



      To fix you problem you can either change job owner to some login that has access to linked server or change SQL Server Agent's service account to domain account that should be mapped on linked server.






      share|improve this answer


























        0












        0








        0








        I have put in "Advanced", "Run as user" as SQLUserName




        This is not the option to use in your case.



        Using this option you can specify the user, not login, to run your sp. However, when you connect to linked server, it's not a database user, but server login that is used, it's "login's current security context" that will be used.



        So in your case all depends on the job's owner. If it's sysadmin, the job is executed under Windows account of your SQL Server Agent, and if it's not sysadmin, the job is executing using job's owner's login.



        From your error it seems that your job's owner is sysadmin, as domainservename$ is used. This is because your Agent is running under Local System or Network Service that when going on the network use your pc's account, domainPCname$.



        To fix you problem you can either change job owner to some login that has access to linked server or change SQL Server Agent's service account to domain account that should be mapped on linked server.






        share|improve this answer














        I have put in "Advanced", "Run as user" as SQLUserName




        This is not the option to use in your case.



        Using this option you can specify the user, not login, to run your sp. However, when you connect to linked server, it's not a database user, but server login that is used, it's "login's current security context" that will be used.



        So in your case all depends on the job's owner. If it's sysadmin, the job is executed under Windows account of your SQL Server Agent, and if it's not sysadmin, the job is executing using job's owner's login.



        From your error it seems that your job's owner is sysadmin, as domainservename$ is used. This is because your Agent is running under Local System or Network Service that when going on the network use your pc's account, domainPCname$.



        To fix you problem you can either change job owner to some login that has access to linked server or change SQL Server Agent's service account to domain account that should be mapped on linked server.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 19 hours ago









        sepupicsepupic

        6,856817




        6,856817






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Database Administrators Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f227451%2fmssql-agent-task-failing-stored-procedure%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            SQL Server 17 - Attemping to backup to remote NAS but Access is denied

            Always On Availability groups resolving state after failover - Remote harden of transaction...

            Restoring from pg_dump with foreign key constraints