Solved

SQL Server Script

Posted on 2009-03-31
10
265 Views
Last Modified: 2012-05-06
I have a script which runs fine on my SQL Server Management Studio, but when I run it from a bat file I get a Error message

Change Database Context to VBScanWDB
Msg 7202, level 11 , state 2, Server MASChiCK\SQLExpress, line 2
Could not find server 'ChickRWJ in sysservers. Exe sp_addlinkedserver to add the server to syservers.

The CHICKRWJ is already linked into the Server so why would I run the addlinkserver  Attached is my SQL Script
sqlcmd -S 64.57.248.239,9998\CHIEF -l 65534 -U sa -P golf  -i C:|name.sql

Open in new window

0
Comment
Question by:daruffin
10 Comments
 
LVL 26

Expert Comment

by:Chris Luttrell
ID: 24032123
Your problem is probably what DB you connect to by default.  Add the specific db to your command string.
0
 
LVL 25

Expert Comment

by:reb73
ID: 24032264
It doesn't look like a problem with DB not being specified in the command, if DB is omitted the default database for the login will  be used automatically (and besides this is the SA login)..

Can you verify if the specified linked server does exist by running the following command using sqlcmd -

select * from master.sys.servers
0
 

Author Comment

by:daruffin
ID: 24032270
Here is the what the script the bat file calls and this works when I run it from SQL Server Express, but when I run it from a bat file I get the error
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

Author Comment

by:daruffin
ID: 24032289
Use VBScanWDB
GO

INSERT INTO ActivityCode
SELECT * FROM [CHICKRWJ].[VBScanWDB].[dbo].[ActivityCode]

INSERT INTO Department
SELECT * FROM [CHICKRWJ].[VBScanWDB].[dbo].[Department]

INSERT INTO Employee
SELECT * FROM [CHICKRWJ].[VBScanWDB].[dbo].[Employee]


INSERT INTO IM2_InventoryItemWhseDetl
SELECT * FROM [CHICKRWJ].[VBScanWDB].[dbo].[IM2_InventoryItemWhseDetl]

INSERT INTO IM3_ItemCosting
SELECT * FROM [CHICKRWJ].[VBScanWDB].[dbo].[IM3_ItemCosting]

INSERT INTO Parts
SELECT * FROM [CHICKRWJ].[VBScanWDB].[dbo].[Parts]

INSERT INTO Settings
SELECT * FROM [CHICKRWJ].[VBScanWDB].[dbo].[Settings]

INSERT INTO WorkTicket
SELECT * FROM [CHICKRWJ].[VBScanWDB].[dbo].[WorkTicket]

INSERT INTO WorkTicketParts
SELECT * FROM [CHICKRWJ].[VBScanWDB].[dbo].[WorkTicketParts]

GO

The Link Server name is CHICKRWJ how come I can run this from a Bat file useing

sqlcmd  -i c:\DELVBScanData.sql
sqlcmd  -i c:\ImportVBscanData.sql

bat file
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 24032420
Probably because the linked server does not exist on "64.57.248.239,9998\CHIEF", but it does on your local box.  
0
 

Author Comment

by:daruffin
ID: 24032622
reb73

when I run this cmd I get a error message stating
SQLcmd" select Unknown option. enter -? for help
0
 

Author Comment

by:daruffin
ID: 24032717
The link server is on my local box and I'm pulling data from the server on the WAN. I can run this script manually but I can't run it from a using a script and executing it from a bat file
0
 
LVL 25

Accepted Solution

by:
reb73 earned 250 total points
ID: 24032734
You have to modify your command as follows (using the -Q switch to issue a commandline query and exit)

sqlcmd -S 64.57.248.239,9998\CHIEF -l 65534 -U sa -P golf  -Q "select * from master.sys.servers"
0
 

Author Comment

by:daruffin
ID: 24032868
I get server_id Name

------------------------------------------------------
------------------------------------------------------
-----------------------------------------------------
------------------------------------------------------
0 MASCHICK\SQLExpress

The ChickRWJ does not exist on my loca master file. I'm not sure why since I link it in and I can pull data from there
0
 

Author Closing Comment

by:daruffin
ID: 31564993
This was what I was looking for it works fine now. Thanks
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Not selecting duplicate data 6 60
Record open by another user 6 64
SQL Restore Script - Syntax Error 8 104
Email Notifications for SQL 2005 9 36
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question