[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

How to use IP address when calling a SQL Store Procedure

Posted on 2010-01-11
8
Medium Priority
?
213 Views
Last Modified: 2012-05-08
Hi,

I am writing a stored procedure which inturn calls many store proc from different servers.

I can use something like DatabaseServerName.Databasename.dbo.Databasetable and it works.

Now i want to use IP instead of databaseservername, something like
100.10.2.3.Databasename.dbo.Databasetable it fails with an exception...

Line 7: Incorrect syntax near '100.10'.

I know i am not prefixing the IP in a proper way...can anybody suggest a proper way to use?

Thanks,
Rithesh
0
Comment
Question by:Star79
8 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 26285719
You need to create a linked server first, then only you can use the 4 part names , you can enclose the names of the sever, db within []
[LinkedServerName].[Databasename].dbo.Databasetable
0
 

Author Comment

by:Star79
ID: 26285761
any other alternatives.
0
 
LVL 61

Expert Comment

by:HainKurt
ID: 26285842
create a mapping on the db

as ip, linkname and use this table to construct your sql, @sqlStatement, and use:

exec sp_executesql @sqlStatement
0
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 26285853
0
 
LVL 61

Accepted Solution

by:
HainKurt earned 2000 total points
ID: 26285871
cant you use ip for linked name and use siomething like this

[100.12.23.45].Databasename.dbo.Databasetable
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 26285955
>cant you use ip for linked name and use siomething like this

But he nee dto create the linked server first
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 26286542
See if OPENROWSET(), OPENDATASOURCE() and/or OPENQUERY() work for you?
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 26329195
does that work without creating the linked server
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

590 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