Using NET command issues in SQL query analysis _mssql

Source: Internet
Author: User
Tags net command
Execute under DOS command (or BAT file):
NET use \\192.168.100.1\ipc$ Ks-c-001-11/user:administrator
COPY \\192.168.100.1\xm\xm\sale_dbc.* c:\temp/y
COPY \\192.168.100.1\xm\xm\sale07.* c:\temp/y
COPY \\192.168.100.1\xm\xm\sale10.* c:\temp/y
COPY \\192.168.100.1\xm\xm\sale11.* c:\temp/y
NET use \\192.168.100.1\ipc$/del
Execute in Query analysis:
1. Using xp_cmdshell, it is best to add "master.dbo." Before the command because the stored procedure "xp_cmdshell" belongs to the master database.
2. When setting up a connection to IPC, the "User:" and "User name" will also be connected to the IP or computer name.
First, use IP address connection
--1. Setting up a connection
EXEC Master.dbo.xp_cmdshell ' net use \\192.168.100.1\ipc$ ks-c-001-11/user:192.168.100.1\administrator '
--2. Execute DOS command
EXEC Master.dbo.xp_cmdshell ' COPY \\192.168.100.1\xm\xm\sale_dbc.* c:\temp/y '
EXEC Master.dbo.xp_cmdshell ' COPY \\192.168.100.1\xm\xm\sale07.* c:\temp/y '
EXEC Master.dbo.xp_cmdshell ' COPY \\192.168.100.1\xm\xm\sale10.* c:\temp/y '
EXEC Master.dbo.xp_cmdshell ' COPY \\192.168.100.1\xm\xm\sale11.* c:\temp/y '
--3. Disconnect
EXEC Master.dbo.xp_cmdshell ' net use \\192.168.100.1\ipc$/del '
second, the use of computer name connection
--1. Setting up a connection
EXEC Master.dbo.xp_cmdshell ' net use \\ks-008\ipc$ ks-c-001-11/user:ks-008\administrator '
--2. Execute DOS command
EXEC Master.dbo.xp_cmdshell ' COPY \\ks-008\xm\xm\sale_dbc.* c:\temp/y '
EXEC Master.dbo.xp_cmdshell ' COPY \\ks-008\xm\xm\sale07.* c:\temp/y '
EXEC Master.dbo.xp_cmdshell ' COPY \\ks-008\xm\xm\sale10.* c:\temp/y '
EXEC Master.dbo.xp_cmdshell ' COPY \\ks-008\xm\xm\sale11.* c:\temp/y '
--3. Disconnect
EXEC Master.dbo.xp_cmdshell ' net use \\ks-008\ipc$/del '

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.