Как подконнектиться к удаленному SQL serverу
Релиб
Форумы       Участники    Календарь    Кто он-лайн?
Добро пожаловать, гость ( Вход | Регистрация )
        



Как подконнектиться к удаленному SQL serverу Expand / Collapse
Автор
Сообщение
14.12.2001 18:47
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

участник
Last Login: 01.05.2003 9:57
Сообщ.: 218, Visits: 2 399
Есть SQL server 6.5 (мой) и SQL server 7 (удаленный). Нужно законнектиться к нему и выполнить select (параметры connectiona известны, можно даже создать ODBC data source). Как это сделать? Объясните чайнику.
Сообщ. #736667
14.12.2001 18:54
Forum Guru

Forum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum Guru

участник
Last Login: 17.04.2003 15:55
Сообщ.: 69, Visits: 760
используй
sp_addlinkedsrv
sp_addlinkedsrvlogin

по моему так, вчера делал доступ MSSQL->Oracle, так уже имена забыл :-), а в SQL Book Online залезать не охота.
Сообщ. #736669
14.12.2001 19:04
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

участник
Last Login: 01.05.2003 9:57
Сообщ.: 218, Visits: 2 399
Проблема в том, что sp_addlinkedserver, sp_addlinkedsrvlogin, а также openrowset и openquery не доступны в 6.5. Можно сделать sp_addserver, но я не очень понимаю, что делать дальше.
Сообщ. #736671
14.12.2001 19:16
Forum Guru

Forum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum Guru

участник
Last Login: 17.04.2003 15:55
Сообщ.: 69, Visits: 760
sp_addserver [@server =] 'server'
[,[@local =] 'local']
[,[@duplicate_ok =] 'duplicate_OK']

Arguments
[@server =] 'server'
Is the name of the server. Server names must be unique and follow the rules for Microsoft Windows NT® computer names, although spaces are not allowed. server is sysname, with no default.
[@local =] 'LOCAL'
Specifies whether the server that is being added is a local or remote server. @local is varchar(10), with a default of NULL. Specifying @local as LOCAL defines @server as the name of the local server and causes the @@SERVERNAME function to return server. (The Setup program sets this variable to the computer name during installation. It is recommended that the name not be changed. By default, the computer name is the way users connect to SQL Server without requiring additional configuration.) The local definition takes effect only after the server is shut down and restarted. Only one local server can be defined in each server.
[@duplicate_ok =] 'duplicate_OK'
Specifies whether or not a duplicate server name is allowed. @duplicate_OK is varchar(13), with a default of NULL. @duplicate_OK can only have the value duplicate_OK or NULL. If duplicate_OK is specified and the server name that is being added already exists, then no error is raised. @local must be specified if named parameters are not used.
Return Code Values
0 (success) or 1 (failure)
----------------------------------------------------------------------
sp_addremotelogin [@remoteserver =] 'remoteserver'
[,[@loginame =] 'login']
[,[@remotename =] 'remote_name']

Arguments
[@remoteserver =] 'remoteserver'
Is the name of the remote server that the remote login applies to. remoteserver is sysname, with no default. If only remoteserver is given, all users on remoteserver are mapped to existing logins of the same name on the local server. The server must be known to the local server (added using sp_addserver). When users on remoteserver connect to the local server running Microsoft® SQL Server™ to execute a remote stored procedure, they connect as the local login that matches their own login on remoteserver. remoteserver is the server that initiates the remote procedure call.
[@loginame =] 'login'
Is the login ID of the user on the local SQL Server. login is sysname, with a default of NULL. login must already exist on the local SQL Server. If login is specified, all users on remoteserver are mapped to that specific local login. When users on remoteserver connect to the local SQL Server to execute a remote stored procedure, they connect as login.
[@remotename =] 'remote_name'
Is the login ID of the user on the remote server. remote_name is sysname, with a default of NULL. remote_name must exist on remoteserver. If remote_name is specified, the specific user remote_name is mapped to login on the local server. When remote_name on remoteserver connects to the local SQL Server to execute a remote stored procedure, it connects as login. The login ID of remote_name can be different from the login ID on the remote server, login.
Return Code Values
0 (success) or 1 (failure)
Сообщ. #736673
14.12.2001 19:21
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

участник
Last Login: 01.05.2003 9:57
Сообщ.: 218, Visits: 2 399
А select как сделать?
Сообщ. #736675
14.12.2001 19:28
Forum Guru

Forum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum Guru

участник
Last Login: 17.04.2003 15:55
Сообщ.: 69, Visits: 760
Executing a Distributed Query
When executing a distributed query against a linked server, include a fully qualified, four-part table name for each data source to query. This four-part name should be in the form linked_server_name.catalog.schema.object_name. For example, to run a “SELECT * FROM employees” query against a SQL Server data file and an Oracle data file, the distributed query would look similar to the following:

SELECT emp.EmloyeeID, ord.OrderID, ord.Discount

FROM SQLServer1.Northwind.dbo.Employees AS emp,

OracleSvr.Catalog1.SchemaX.Orders AS ord

WHERE ord.EmployeeID = emp.EmployeeID

AND ord.Discount > 0
Сообщ. #736677
14.12.2001 19:33
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

участник
Last Login: 01.05.2003 9:57
Сообщ.: 218, Visits: 2 399
distributed query в 6.5 тоже нет (можешь убедиться, посмотрев new features в books online по 7.0). :(
Сообщ. #736678
14.12.2001 19:37
Forum Guru

Forum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum Guru

участник
Last Login: 17.04.2003 15:55
Сообщ.: 69, Visits: 760
Ну ты же можешь использовать полные имена в секции FROM:

[[[server.][database].][owner_name].]object_name
Сообщ. #736679