Link to home
Start Free TrialLog in
Avatar of Star79
Star79Flag for United States of America

asked on

How to use IP address when calling a SQL Store Procedure

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
Avatar of Aneesh
Aneesh
Flag of Canada image

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
Avatar of Star79

ASKER

any other alternatives.
create a mapping on the db

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

exec sp_executesql @sqlStatement
ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada 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
>cant you use ip for linked name and use siomething like this

But he nee dto create the linked server first
See if OPENROWSET(), OPENDATASOURCE() and/or OPENQUERY() work for you?
does that work without creating the linked server