Establish different database connection servers

Source: Internet
Author: User

Use Microsoft ole db provider for ODBC to link MySQL

Install MySQL ODBC driver myodbc

1. Create an ODBC data source for MySQL. For example, set database to test and data source name to mydsn.

2. Create a linked Database

Exec sp_addmediaserver @ Server = 'mysqltest', @ srvproduct = 'mysql', @ provider = 'msdasql ', @ datasrc = 'mydsn'

Go

Exec sp_add1_srvlogi @ rmtsrvname = 'mysqltest', @ useself = 'false', @ locallogin = 'sa ', @ rmtuser = 'mysql Username', @ rmtpassword = 'mysql password'

3. query data

Select * From openquery (mysqltest, 'select * From table ')

This is not acceptable below:

Select * From openquery (mysqltest, 'table ')

Note: you cannot directly use select * from to link the server name, database name, username, table (or view)

The four-part name query data may be a bug.

2. Use Microsoft ole db provider for Oracle to connect to Oracle

1. Create a linked Database

Sp_addmediaserver 'Alias ', 'oracle', 'msdaora ', 'service name'

Go

Exec sp_add1_srvlogin @ rmtsrvname = 'Alias ', @ useself = 'false', @ locallogin = 'sa', @ rmtuser = 'oracle username', @ rmtpassword = 'Password'

2. query data

Select * from alias. username. Table (view)

Note: All the four parts are in uppercase.

3. Execute the Stored Procedure

Use openquery:

Select * From openquery (alias, 'exec user name. Stored Procedure name ')

3. Set the link server to access formatted text files

Microsoft ole db for jet provides Program It can be used to access and query text files.

To directly create a link server to access a text file without linking the file to a table in the access. MDB file, execute sp_addmediaserver, as shown in the following example.

The provider is Microsoft. Jet. oledb.4.0, and the provider string is "text ". The data source is the complete path name of the directory containing text files. The schema. ini file (the structure of the text file) must exist in the same directory as the text file. For more information about creating the schema. ini file, see the Jet Database Engine documentation.

-- Create a linked server.

Exec sp_addmediaserver txtsrv, 'Jet 4.0 ',

'Microsoft. Jet. oledb.4.0 ',

'C: datadistqry ',

Null,

'Text'

Go

-- Set up login mappings.

Exec sp_add1_srvlogin txtsrv, false, null, admin, null

Go

-- List the tables in the linked server.

Exec sp_tables_ex txtsrv

Go

-- Query one of the tables: file1 # txt

-- Using a 4-part name.

Select * From txtsrv... [file1 # TXT]

4. Link to the SQL Server:

1. Use the ODBC Microsoft ole db Provider

Exec sp_addmediaserver 'Alias ', '', 'msdasql', null, null, 'driver = {sqlserver}; server = remote name; uid = user; Pwd = password ;'

If the @ catalog parameter is added, you can specify the database

Exec sp_add1_srvlogin @ rmtsrvname = 'aliased ', @ useself = 'false', @ locallogin = 'sa', @ rmtuser = 'sa ', @ rmtpassword = 'Password'

2. Use SQL Server's Microsoft OLE DB Provider

Exec sp_addlinkedserver @ Server = 'Alias ', @ provider = 'sqlodb', @ srvproduct = '', @ datasrc = 'remote server name'

Exec sp_addjavassrvlogin @ rmtsrvname = 'wzb', @ useself = 'false', @ locallogin = 'sa ', @ rmtuser = 'sa', @ rmtpassword = 'Password'

Then you can:

Select * from alias. Database Name. DBO. Table Name

Insert database name. DBO. Table Name select * from alias. Database Name. DBO. Table Name

Select * into database name. DBO. New table name from alias. Database Name. DBO. Table Name

Go

Example 1,

In this example, create a linked server named s1_instance1 on the SQL server instance,

This server uses the Microsoft ole db provider of SQL Server.

Exec sp_addmediaserver @ Server = 's1 _ instance1 ', @ srvproduct = '', @ provider = 'sqloledb', @ datasrc = 's1instance1'

Example 2,

-- Create a linked server

Exec sp_addmediaserver 'xiaoming', '', 'msdasql ', null, null, 'driver = {sqlserver}; server = 192.168.0.1; uid = sa; Pwd = 123 ;'

-- Create a login ing for the linked server

Exec sp_addmediasrvlogin @ rmtsrvname = 'xiaoming', @ useself = 'false', @ locallogin = 'sa ', @ rmtuser = 'sa', @ rmtpassword = '2016'

Go

-- Query data

Select * From Xiaoming. schooladmin. DBO. Agent

-- Delete the link Server login ing and link Server:

Exec sp_droplinkedsrvlogin 'xiaoming', 'sa'

Exec sp_dropserver 'xiaoming'

Note:

Set identity_insert [database. [owner.] {table} {on | off}

Therefore, you cannot set this attribute by connecting to the server.

This problem also exists in.

Select * into Xiaoming. northwind. DBO. tt from

Xiaoming. northwind. DBO. TT

5. Set the linked server to access the ACCESS database

Use the Microsoft ole db provider for jet

In this example, create a linked server named test.

This example assumes that Microsoft Access and the example northwind database have been installed, and

The northwind database resides in C :.

Use master

Go

-- To use named parameters:

Exec sp_addmediaserver

@ Server = 'test ',

@ Provider = 'Microsoft. Jet. oledb.4.0 ',

@ Srvproduct = 'ole DB provider for jet ',

@ Datasrc = 'C: northwind. mdb'

Go

-- Or to use no named parameters:

Use master

Go

Exec sp_addmediaserver

'Test ',

'Ole DB provider for jet ',

'Microsoft. Jet. oledb.4.0 ',

'C: northwind. mdb'

Go

Use

Select * from test... table name

6. Connect to Sybase

-- First, you need to attach the SQL Server to access the Sybase client.

-- Create a linked server

Exec sp_add1_server 'sybase1 ', '', 'msdasql', null, null, 'driver = {Sybase system11}; database = hisdb; srvr = 10.211.135.12; uid = sa; pwd = 1111 ;'

Usage:

Select * From sybase1.hisdb. DBO. Table1

Method 2

Use ODBC

Implementation of connecting SQL Server to Sybase Server

Author: ccbzzp

The test environment in this article is:

Operating System: Windows2000 Server (Traditional Chinese System)

Install the database: sqlserver2000 (English version) and sybase8.0 client (English version)

Specific steps:

1. Install sybase8.0 client software and sqlserver2000 software on the PC.

2. Configure the ODBC data source for Windows:

Choose "start"> "program set"> "System Management Tools"> "Data Source" (ODBC) "> enter the user DSN or system DSN: add> select Adaptive Server anywhere8.0> Custom Data Source Name (for example, sybasetest)> Database Name (required !) -> OK.

3. Select the name of the data source you Just configured, and then select Configuration to jump out of sybasetest messages:

The data source is not connected. Connecting to the data source will

Provide useful information during configuration. wocould you like

Connect to the data source?

Select Yes (OK or OK ).

Go to the connect to Sybase Database screen:

User ID: user who entered Sybase Database

Password: enter the password of the Sybase Database User.

Connection Mode: You can select the default share mode.

Select OK!

ODBC configuration and test completed!

4. Configure the connection server in sqlserver2000:

Enterprise Manager> Security> connect to the server> right-click to create a connection Server> define a connection name; select another data source; specify the program name as Sybase Adaptive Server Anywhere provider8.0; the product name is optional. The data source specifies the name of the data source defined in ODBC. The provider string is in the following format: User ID = username; Password = userpasswd

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.