SQL Server error 2812: unable to find the stored procedure sp_password

Source: Internet
Author: User
Tags sql server query

Cause analysis

If the stored procedure 'sp _ Password' is not found, the sp_password stored procedure in sqlserver is missing. You only need to create a new sp_password stored procedure.


Re-create the sp_passsword Stored Procedure Code (use WINDOWS identity verification to log on to the SQL SERVER query tool.
Copy-paste-execute and pull) run

The code is as follows: Copy code

-- SQL code starts

Sp_configure 'allow updates', 1
RECONFIGURE WITH OVERRIDE

Go

Use master
Go

If exists (select * from dbo. sysobjects where id = object_id (n' [dbo]. [sp_password] ') and OBJECTPROPERTY (id, n' IsProcedure') = 1)
Drop procedure [dbo]. [sp_password]
Go

Create procedure sp_password
@ Old sysname = NULL, -- the old (current) password
@ New sysname, -- the new password
@ Loginame sysname = NULL -- user to change password on
As
-- Setup runtime options/declare variables --
Set nocount on
Declare @ self int
Select @ self = case when @ loginame is null THEN 1 ELSE 2 END

-- RESOLVE LOGIN NAME
If @ loginame is null
Select @ loginame = suser_sname ()

-- Check permissions (SecurityAdmin per Richard Waymire )--
IF (not is_srvrolemember ('securityadmin') = 1)
AND not @ self = 1
Begin
Dbcc auditevent (107, @ self, 0, @ loginame, NULL)
Raiserror (15210,-1,-1)
Return (1)
End
ELSE
Begin
Dbcc auditevent (107, @ self, 1, @ loginame, NULL)
End

-- Disallow user transaction --
Set implicit_transactions off
IF (@ trancount> 0)
Begin
Raiserror (15002,-1,-1, 'sp _ password ')
Return (1)
End

-- Resolve login name (disallows nt names)
If not exists (select * from master. dbo. syslogins where
Loginname = @ loginame and isntname = 0)
Begin
Raiserror (15007,-1,-1, @ loginame)
Return (1)
End

-- IF non-sysadmin attempting change to sysadmin, require password (218078 )--
If (@ self <> 1 AND is_srvrolemember ('sysadmin') = 0 AND exists
(SELECT * FROM master. dbo. syslogins WHERE loginname = @ loginame and isntname = 0
AND sysadmin = 1 ))
SELECT @ self = 1

-- Check old password if needed --
If (@ self = 1 or @ old is not null)
If not exists (select * from master. dbo. sysxlogins
Where srvid is null and
Name = @ loginame and
(@ Old is null and password is null) or
(Pwdcompare (@ old, password, (case when xstatus & 2048 = 2048 THEN 1 ELSE 0 END) = 1 )))
Begin
Raiserror (15211,-1,-1)
Return (1)
End

-- Change the password --
Update master. dbo. sysxlogins
Set password = convert (varbinary (256), pwdencrypt (@ new), xdate2 = getdate (), xstatus = xstatus &(~ 2048)
Where name = @ loginame and srvid IS NULL

-- Update protection timestamp for master db, to indicate syslogins change --
Exec ('use master grant all to Null ')

-- FINALIZATION: return success/FAILURE --
If @ error <> 0
Return (1)
Raiserror (15478,-1,-1)
Return (0) -- sp_password

GO
Sp_configure 'allow updates', 0
RECONFIGURE WITH OVERRIDE

-- SQL code ended

If the problem persists, run the following code directly in the query analyzer.

Code

The code is as follows: Copy code

Use master
Go
Create procedure sp_dropextendedproc --- 1996/08/30 20:13
@ Functname nvarchar (517) -- name of function
As
/*
** If we're in a transaction, disallow the dropping of
** Extended stored procedure.
*/
Set implicit_transactions off
If @ trancount> 0
Begin
Raiserror (15002,-1,-1, 'sp _ dropextendedproc ')
Return (1)
End

/*
** Drop the extended procedure mapping.
*/
Dbcc dropextendedproc (@ functname)
Return (0) -- sp_dropextendedproc

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.