SQL server SQL Agent service usage Summary

Source: Internet
Author: User
Tags mssqlserver
1. start or stop the SQL Agent service in the query analyzer.
  Start

Use master
Go
Xp_cmdshell 'net start sqlserveragent'

  Stop

Use master
Go
Xp_cmdshell 'net stop sqlserveragent'

  Change the service start mode from manual to automatic start Mode

Exec xp_cmdshell 'scm-action 7-service MSSQLServer-svcstarttype 2'

You can also directly use the command line to execute the content in quotation marks.

  2. Causes and handling of abnormal startup
On the surface, the SQL Server Agent service is started normally, but the following error occurs when you view the job attributes and job history:
Error 14258: SQLServerAgent cannot be started. Please try again later.

Possible causes:
"Use Windows NT fiber" is selected. The specific cause is unknown.

Solution:
Enterprise Manager -- Right-click SQL instance -- properties -- Processor -- deselect "use Windows NT fiber"
Then restart the SQL service.

  System Password modified
Solution:
A. My computer -- control panel -- Management Tools -- services -- Right-click MSSQLServer -- properties -- login identity -- select "Local SYSTEM account"
Or:
B. my computer -- control panel -- Administrative Tools -- service -- Right-click MSSQLServer -- properties -- login identity -- select "this account" -- select administrator, enter your administrator password in the password and Confirm Password.

  Differences between the two:
Select the first method. The administrator password will be changed later. You do not need to adjust the password (but the system administrator is required to log on to the operating system)

  An error occurred while the database was DOWN.
Solution:
Use the installation CD to reinstall the registry, select 'advanced option'-'rebuild registry ', and then proceed all the way ......

/*
** Get whether a service is started

Home
Haok. Y

** 2004-10-20
Determine whether a service is started based on the results returned by net start.

** Example
Declare @ isonworking bit
Exec spserviceisonworking 'mssql $ newinstance ', @ isonworking output
Select @ isonworking

*/
Create procedure spserviceisonworking
(
@ Servicename varchar (100 ),
@ Isonworking bit output
)
As
Set nocount on

Create Table # output
(
Ot varchar (100)
)

Insert into # output
Exec master.. xp_mongoshell 'net start'

Set @ isonworking =
Case
When exists (
Select top 1 1
From # output
Where ot like '%' + @ servicename + '%'
) Then 1
Else 0
END

Drop table # Output

SET NOCOUNT OFF
GO

The SQL Distributed Relational object (SQL-DMO) Library allows your VB6 applications to automatically interact with the SQL server. This is useful for obtaining information about SQL servers, such as the server status or available servers on the network.


<Br/>


To use the SQL-DMO library, you need to set a reference to the "Microsoft SQL-DMO Object Library.

ApplicationObjectListAvailableSQLServersMethod returnsNameListObject that contains a list of available servers on the network. The following code shows how to use this method to fill the list box control:

Dim objSQLApp As SQLDMO. Application
Dim objNameList As SQLDMO. NameList
Dim intCount As Integer

Set objSQLApp = New SQLDMO. Application

Set objNameList = objSQLApp. ListAvailableSQLServers ()

For intCount = 1 To objNameList. Count
Call List1.AddItem (objNameList. Item (intCount ))
Next

Another useful object in the SQL-DMO library isSQLServerObject. This object can be used to obtain information about a specific SQL server.ConnectThe method establishes a connection to the database server and accepts three parameters: Database Name, user name, and password. Once the object connection is successful, information about the server can be retrieved:

Dim objSQLServer As SQLDMO. SQLServer

Set objSQLServer = New SQLDMO. SQLServer
ObjSQLServer. LoginSecure = True
Call objSQLServer. Connect ("MyServerName", "username", "password ")

Debug. PrintobjSQLServer. Name
Debug. PrintobjSQLServer. HostName
Debug. PrintobjSQLServer. Status

Restore the xp_cmdshell

Required tools: SQL Query Analyzer and SqlExec Sunx Version
  
Part 1:
  
Summary on How to Remove xp_cmdshell to protect the system:
First, let's know the statement:
1. To remove the xp_cmdshell extension process, use the following statement:


      if exists (select * from dbo.sysobjects where id=object_id(N'[dbo].[xpcmdshell]') and OBJECTPROPERTY(id,N'IsExtendedProc')=1)exec sp_dropextendedproc N'[dbo].[xp_cmdshell]'


2. To add the xp_cmdshell extension process, use the following statement:

      sp_addextendedproc xp_cmdshell,@dllname='xplog70.dll'


Now let's look at the phenomenon:
After obtaining the SA permission, we remotely use Sqlexec to execute the cmd command, and the prompt SQL _ERROR is displayed. Therefore, xp_mongoshell may be removed.
Now let's take a look at the two methods to restore after xp_cmdshell is removed:
  
Method 1: use SQL Query Analyzer to connect to the other party and write data directly. It is very convenient to sp_addextendedproc xp_cmdshell, @ dllname = 'loglog70. dll'
Method 2: Use SqlExec Sunx Version to first fill in % s in the Format option of SqlExec Sunx Version, and enter sp_addextendedproc 'xp _ javasshell' and 'sqlsql70 In the CMD option. dll 'or use sp_addextendedproc 'xp _ shortshell' and 'xp log70. dll 'In addition, use SqlExec Sunx Version to remove the xp_mongoshell method and select the same conditions when adding the method. Then enter sp_dropextendedproc 'xp _ mongoshell'.

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.