Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Pls Help - Urgent handling "-" in query

Author  Topic 

vbseeker
Starting Member

8 Posts

Posted - 2004-06-25 : 06:14:57
Hi,

i am using sp_addlinkedserver to connect with my another server.
Let say my current server name is anand and other server name is anand-new

now sp_addlinkedserver worked ok

Now i want to fetch some record from the anand-new server.

I am writing my query in I server (i.e. Anand)


SELECT TOP 10 * FROM anand-new.NEWSITE.DBO.Xyz_NEW

I am getting error

Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near '-'.


Pls help

Its urgent

Cheers,
Anand

nr
SQLTeam MVY

12543 Posts

Posted - 2004-06-25 : 06:16:20
SELECT TOP 10 * FROM [anand-new].NEWSITE.DBO.Xyz_NEW

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

vbseeker
Starting Member

8 Posts

Posted - 2004-06-25 : 07:29:43
hi,

Thanks for the reply.

Now i am facing one more problem.
Not able to connect the two sql servers.

Lets say there are two servers.

X with ip- 209 US Server
Y with ip -203 INDIA server

How i can connect these two server.

All the below things are being done at SERVER-X
I am using sp_addlinkedserver

exec sp_addlinkedserver 'Server-Y'
EXEC sp_addlinkedsrvlogin 'Server-Y', 'false', NULL, 'sa', 'xxxxxx'
I can see the enter in the sysservers in the master database

But when i exectue the query

SELECT TOP 10 * FROM [anand-new].NEWSITE.DBO.Xyz_NEW

Server: Msg 17, Level 16, State 1, Line 1
SQL Server does not exist or access denied.

Pls help.

Anand



Go to Top of Page

Pat Phelan
Posting Yak Master

187 Posts

Posted - 2004-06-25 : 13:02:07
Just for the jolly factor, let's try the simple case first. Please try:
EXECUTE master.dbo.xp_cmdshell 'ping anand-new'
to see if you have basic tcp/ip connectivity between the servers. If that works, then try:
SELECT TOP 1 * FROM [anand-new].master.dbo.sysprocesses
to see if you have basic SQL connectivity.

-PatP
Go to Top of Page

vbseeker
Starting Member

8 Posts

Posted - 2004-06-26 : 01:12:14
Hi,

EXECUTE master.dbo.xp_cmdshell 'ping Anand-Server'


I tried doing it. But getting the following response



Unknown host Anand-Server
NULL

Should i use first the sp_addlinkedserver or something else before pinging.

Cheers,
Anand
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-06-26 : 01:36:55
No need for anything before pinging. Basically the SQL box you are connecting to cannot see "Anand-Server"

You could try the PING with the IP number of "Anand-Server" instead.

If that works you can try making a linked server using the IP address (or if you hsve access to the server you could set up an "alias" with a nice pretty name!)

Then try:

SELECT TOP 1 * FROM [111.122.133.144].master.dbo.sysdatabases

Otherwise possibly something from the following snippets may help


-- Create a Linked Server
-- Use this script to create a linked server by "Find&Replace" of key tokens

-- History
-- 26-Mar-2004 KBM Started

-- Globally change the following:

-- IP Address: 111.222.333.444
-- Remote server name: MyRemoteServer
-- (This can be IP address in the format 123.456.789.123
-- or name like SERVERNAME.HOSTS.MYDomain.COM)

-- User Login: MyUserID
-- User Password: MyPassword
-- (This should be a database login available on both machines with the same password)


-- *** Having done Find&Replace of parameters (above), highlight each section (below) and execute

USE master
GO

-- Show linked servers
EXEC sp_linkedservers


-- EXEC sp_helpserver -- (Also shows services etc.

-- Delete any existing linked-server attempt (optional)
EXEC sp_dropserver
@server = 'MyRemoteServer',
@droplogins = 'droplogins' -- 'droplogins' = Drop associated logins, NULL=Do not drop logins


-- Create Linked Server
EXEC sp_addlinkedserver
@server = 'MyRemoteServer' -- local name of the linked server to create.
-- If data_source is not specified, server is the actual name of the instance
, @srvproduct = 'SQL Server' -- product name of the OLE DB data source to add as a linked server
-- If "SQL Server", provider_name, data_source, location, provider_string, and catalog do not need to be specified.
-- Execute ONLY to here IF you are connecting two SQL servers
,@provider = 'SQLOLEDB' -- unique programmatic identifier of the OLE DB provider (PROGID)
,@datasrc = 'MyRemoteServer' -- name of the data source as interpreted by the OLE DB provider (DBPROP_INIT_DATASOURCE property)


-- Remove existing Linked Server Login
EXEC sp_droplinkedsrvlogin @rmtsrvname = 'MyRemoteServer'
, @locallogin = 'MyUserID'


-- Create Linked Server Login
EXEC sp_addlinkedsrvlogin @rmtsrvname = 'MyRemoteServer'
, @useself = 'false' -- true=Connect using current UserID/Password, false=use rmtuser/rmtpassword below
, @locallogin = 'MyUserID' -- NULL=All local logins use this remote login account, otherwise local login UserName being set up (repeat for each one required)
-- Execute ONLY to here IF @UseSelf='TRUE' (above)
, @rmtuser = 'MyUserID' -- UserName on Remote corresponding to this @LocalLogin.
, @rmtpassword = 'MyPassword' -- Ditto password



-- Test connection - should list databases on remote machine
select top 10 name from [MyRemoteServer].master.dbo.sysdatabases



-- If you get this error message:
-- "Server '111.222.333.444' is not configured for DATA ACCESS"
-- then execute this statement
exec sp_serveroption 'MyRemoteServer', 'data access', 'true'

-- Test again!
select top 10 name from [MyRemoteServer].master.dbo.sysdatabases


-- Failing that try to PING the remote server (by Extended Procedure Command line call)
-- if that fails then your SQL box cannot see the remote server
exec master.dbo.xp_cmdshell 'PING 111.222.333.444'

Kristen
Go to Top of Page

vbseeker
Starting Member

8 Posts

Posted - 2004-06-26 : 01:50:10
Hi,

10x for the info.

If used the below command.
exec master.dbo.xp_cmdshell 'PING xxx.xxx.xxx.xxx'

What if My ISP provider has blocked the ICMP.

What is the other way out.

Cheers,
Anand

Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-06-26 : 02:00:25
What does the PING test come back with?

Kristen
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-06-26 : 22:50:57
If you can't ping using that, then you need to contact your ISP profider. The xp_cmdshell will give you the same results a PING from the command prompt window will.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page
   

- Advertisement -