Link to home
Start Free TrialLog in
Avatar of daruffin
daruffin

asked on

SQL Server Script

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

Avatar of Chris Luttrell
Chris Luttrell
Flag of United States of America image

Your problem is probably what DB you connect to by default.  Add the specific db to your command string.
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
Avatar of daruffin
daruffin

ASKER

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
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
Probably because the linked server does not exist on "64.57.248.239,9998\CHIEF", but it does on your local box.  
reb73

when I run this cmd I get a error message stating
SQLcmd" select Unknown option. enter -? for help
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
ASKER CERTIFIED SOLUTION
Avatar of reb73
reb73
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
This was what I was looking for it works fine now. Thanks