Solved

SQL Server Script

Posted on 2009-03-31
10
270 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 27

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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

623 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