Solved

SQL Server Script

Posted on 2009-03-31
10
257 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
 

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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now