Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
23 views

Configuring Microsoft SQL Server 2005 Li

Uploaded by

Eduardo Henry
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Configuring Microsoft SQL Server 2005 Li

Uploaded by

Eduardo Henry
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Configuring Microsoft SQL Server 2005 “Linked Server” with Sybase Organic

OLE DB Provider

By Wayne Smith

Linked Servers will allow you to submit a TSQL statement from one SQL Server
instance, retrieving the data from an ASE Server instance via the ASE OLE DB Provider.
In fact, linked server can be used to join data from multiple ASE Server instances using a
single TSQL statement. Sybase’s OLEDB provider comes in two Windows platform
versions: 32 bit and 64 bit. In this walk thru we’ll use the ASE OLE DB 32 bit provider
from the SDK 15.0. The reason for using the OLEDB Provider is to avoid using the ASE
ODBC driver through the use of the MSDASQL (Microsoft OLE DB Provider for ODBC
Drivers) provider, which translates OLE DB API calls to ODBC API calls. Remember to
think of the MSDASQL provider as an OLE DB to ODBC bridge even though it is fully
supported. This adds an additional translation layer, only adding additional traffic and
delays to the process. The bottom line: it’s a little slower. I would recommend going
with the native ASE OLE DB 32 bit or 64 bit providers as they are much faster and easier
to use.

Prerequisite:
Sybase SDK 15.0 32 bit or 64 bit with ESD#12 or 12.5.1 32 bit ESD#22
Sybase ASE 12.5.4 or 15.0 with the latest ESD’s installed.
Microsoft SQL Server Management Studio Express 2005 9.00.2047.00
Microsoft Data Access Components (MDAC) 2000.085.1117.00
Microsoft Windows XP/2003 (Minimum: xpsp_sp2_rtm.040803-2158) For the
Operating System make sure you have the latest Service Pack installed.

The following is a real “MUST” otherwise the driver will fail. On all ASE Server
versions you will have to update the ASE Schema tables for the stored procedures for the
ASE OLE DB provider. Please go to the Scripts directory (sp) and run the following
command:

C:>Sybase\DataAccess\OLEDB\SP\install_oledb_sprocs.bat servname userID password.

The script will update the tables on the ASE that the ASE OLE DB provider uses to
interpret the metadata correctly. The script has to have version of ASEOLE DB MDA
Scripts 15.0.0.162/Mon 06-11-2007 13:37:02.67 or higher. You can check your version
by running the sp_version on the ASE via isql. The OLE DB provider itself needs to be at
least ESD#11 or higher. Also, you have to turn ON the "Enable Dynamic Prepare"
property in the OLEDB Data Administrator property from the 'Connection' tab or at the
Provider Options dialog (see figure 2).

Depending on the user account information local Users verses Domain user account,
you’ll have to adjust your DCOM settings that MS-SQL uses to perform RPC.
You should add your domain account to the DCOM. You don’t need a local account.
If you have a local account and not a domain account then add that to the DCOM.
If you use local and domain then I would add the two to the DCOM.

Here are the DCOM configuration steps that Microsoft recommends and the steps
we took to get the Sybase OLEDB provider working out of process.
=============================================================

1. Open the DCOM Configuration utility by going to Start - Run and type dcomcnfg
2. Expand Component Services/Computers/My Computer
3. Right click on My Computer and select Properties.
4. On the Default Properties tab, check the following.
a. Make sure that “Enable Distributed COM on this computer” is checked
b. Make sure that Default Authentication Level = Connect
c. Make sure that Default Impersonation Level = Identify or Impersonate
5. On the COM Security tab, check the following:
a. In the Access Permissions section, click the Edit Limits and Edit Default
buttons
b. Under each button, make sure that the local group containing the SQL Service
account or the SQL Service account itself has Allow on all permissions
c. In the Launch and Activation Permissions section, click the Edit Limits and Edit
Default buttons
d. Under each button, make sure that the local group containing the SQL Service
account or the SQL Service account itself has Allow on all permissions
6. On the Default Protocols tab, check the following:
a. Check to verify that Connection-oriented TCP/IP exists in the DCOM Protocols
7. On the MSDTC tab, click on the Security Configurations button and check the
following options:
a. Make sure that Network DTC Access is checked.
b. Make sure that Allow Remote Clients is checked.
c. Make sure that Allow Inbound is checked.
d. Make sure that Allow Outbound is checked.
e. Make sure that Enable XA transactions is checked.
f. Make sure that the No Authentication Required radio button is selected.
8. After implementing the changes reboot the server for the changes to take affect.

After that is all done we can now start creating a link server connection.
In this test we are going to us a DSN-less connection, bypassing the OLE DB
Connection Manager. You can also create an ASE OLE DB DSN if you need to.
Setting up the Provider
1. Start the Enterprise Manager and then access the server you want to configure.
2. Click the plus sign (+) next to the server's Security folder.
3. Right-click the Linked Servers entry and from the shortcut menu open the folder called
Providers.
4. Highlight the ASEOLEDB and then right click and go to properties (see Figure 1).
Uncheck all the properties except for Dynamic Prepare (see figure 2).
Fig1.
Fig2.
Configuring the Link Server to use the Sybase ASE OLE DB Data Source

Adding Linked Servers


If you want a server to be able to use distributed queries, distributed transactions,
or RPCs (or all three), you must configure linked server connections to other servers.
For example, if clients that access a sql server named vista make distributed queries to
mysybase (ASE), you'll want to configure mysybase as a linked server on vista. To add
a linked server, complete the following steps:

1. Start Enterprise Manager and then access the server you want to configure
2. Click the plus sign (+) next to the server's Security folder.
3. Right-click the Linked Servers entry and from the shortcut menu, choose New Linked
Server. This opens the dialog box shown in Figure 3
4. In the Linked Server field, type the name of the linked server to create
5. If you're linking to an ASE, select the Sybase OLEDB Provider. If you're linking to a
different data source, select the Other Data Source option button and then configure the
data source using the input fields provided. You can't configure unavailable fields for
the selected provider. The available fields are summarized as follows:
Provider Name Use the drop-down list box to select the name of the Sybase ASE OLE
DB Provider to use when communicating with the specified linked server, in this case
“Sybase OLEDB Provider”
Product Name Set the server product name to ASEOLEDB.
Data Source Provider Leave Blank.
Provider String Sets a provider-specific connection string that identifies a unique data
source Example: Server= mysybase;Port=4101;User ID=test;Password=testing;
(See Figure 3)

Server Options
Collation compatible controls sort order settings. If you don't select this option, SQL
Server uses the local sort order. This affects the order of result sets, and you should note
it when you develop SQL Server applications or configure clients. Leave it to the default
setting Blank.
Data Access Set this option to enable the linked server for distributed query access. Set it
to true.
RPC Set this option to enable remote procedure calls from the linked server. Set it to true
RPC Out Sets this option to enable RPC to the linked server. Set it to true.
Use Remote Collation Set this option to have SQL Server use the collation from the
linked server's character columns. If you don't set this option, SQL Server interprets data
from the linked server using the default collation of the local server instance. Note that
only the SQL Server databases take advantage of this option. Set it to true
Collation Name Set this option to assign a specific collation for queries and transactions.
Note that you must clear the Collation Compatible check box before you can set this
option. Leave this blank since we want to use Collation Compatible.
Connection Timeout Sets the timeout value for connections made to the remote. Leave it
to the default setting. See Figure 5
Query Timeout Sets the timeout for queries made to the remote server. Leave it to the
default setting. Click OK to create the linked server.

Next, you'll need to configure security settings for the linked server. Go to the security
page (still on Linked Server Properties). Select 'Be made using this security context'.
Type a login and password that exists on the remote ASE server. You don’t have to have
the same user name and password on MS-SQL and ASE, MS-SQL will get the RPC
permissions from DCOM to execute and at connection time MS-SQL will pass the user
name and password you configure here or what you defined in the connection string. If
you defined the user name and password in the connection string then use ‘Be Made With
out using a security context’. Either way will work just fine. (See Figure 4).

Here is a sample script to create the Sybase OLEDB link.


NOTE: The real server address is nutmeg listening on port 5000 in the @provstr=.
/****** Object: LinkedServer [MYSYBASE] Script Date: 12/04/2007 08:55:26 *****/
/* Note the first line add the Link server and the reference for the connection string **/
EXEC master.dbo.sp_addlinkedserver @server ='mysybase', @srvproduct=N
'ASEOLEDB', @provider=N'ASEOLEDB',
@provstr=N'Server=nutmeg;Port=5000;UID=sa;PWD=;', @catalog=N'pubs2'
/* For security reasons the linked server remote logins password is changed with
######## *//* This link is add the information the MS-SQL */
EXEC master.dbo.sp_addlinkedsrvlogin
@rmtsrvname=N'MYSYBASE’,@useself=N'False',@locallogin=NULL,@rmtuser=NUL
L,@rmtpassword=NULL
GO
EXEC master.dbo.sp_serveroption @server=N' MYSYBASE ', @optname=N'collation
compatible', @optvalue=N'true'
GO
EXEC master.dbo.sp_serveroption @server=N' MYSYBASE ', @optname=N'data
access', @optvalue=N'true'
GO
EXEC master.dbo.sp_serveroption @server=N' MYSYBASE ', @optname=N'dist',
@optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N' MYSYBASE ', @optname=N'pub',
@optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N' MYSYBASE ', @optname=N'rpc',
@optvalue=N'true'
GO
EXEC master.dbo.sp_serveroption @server=N' MYSYBASE ', @optname=N'rpc out',
@optvalue=N'true'
GO
EXEC master.dbo.sp_serveroption @server=N' MYSYBASE ', @optname=N'sub',
@optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N' MYSYBASE ', @optname=N'connect
timeout', @optvalue=N'0'
GO
EXEC master.dbo.sp_serveroption @server=N' MYSYBASE ', @optname=N'collation
name', @optvalue=null
GO
EXEC master.dbo.sp_serveroption @server=N' MYSYBASE ', @optname=N'lazy
schema validation', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N' MYSYBASE ', @optname=N'query
timeout', @optvalue=N'0'
GO
EXEC master.dbo.sp_serveroption @server=N' MYSYBASE ', @optname=N'use remote
collation', @optvalue=N'true'

Fig3

If you get an error 7303 it is due to the fact that the Product name is wrong
make sure you type ASEOLEDB as it is in Fig 3

Fig4
Fig5 Note all the options are set to true.

In Figure6, You can now tree down the newly created link server and see all the
databases and tables in each linked server. If you can’t tree down or you get an error
check your log in user name and password and make sure they are matched up with the
ASE you are connecting to.

Fig6

It’s better to Drop the Link Server than it is to delete it.


Keep in mind MS-SQL loves to cache up everything. If you delete some thing and it’s
still not working odd’s are it’s cached up. Recycling can help. I would recommend if you
need to drop an entire link server mysybase, for example, you can do so with the
sp_dropserver command. All the logins associated with that server must first be dropped
before the server itself can be dropped, but the easy way to do that is to specify the
'droplogins' parameter of the sp_dropserver stored procedure, which does the hard work
for you.
Here is an example:
IF EXISTS (SELECT srv.name FROM sys.servers srv WHERE srv.server_id != 0 AND
srv.name = N'MYSYBASE')EXEC master.dbo.sp_dropserver @server=N'MYSYBASE',
@droplogins='droplogins'

Types of example query’s that can be used with the Sybase ASE via the Sybase ASE
OLE DB Provider and the MS-SQL 2005 link Server.

Four part naming.


SELECT * FROM mysybase.pubs2.dbo.authors
Open Query select statement
select * from openquery (mysybase,'select * from publishers')

Execute statements. Using EXECUTE with a remote stored procedure.


The following example executes the sysdatabases stored procedure on the remote
server ASE Server nutmeg and stores the return status that indicates success or failure in
@retstat. EXEC ('select * from master..sysdatabases') AT MYSYBASE

Delete statements. Sybase fully supports the IRowsetLocate and IRowsetChange


interfaces on the rowset opened through IOpenRowset and IOpenRowset on the table
being updated or deleted.
delete from mysybase.pubs2.dbo.bp_emp_parent_acct_xref_rrXXX

Insert Statements. Sybase fully supports the IRowsetChange interface on the row set
opened through IOpenRowset on the table that is having data inserted into it. The
IRowsetChange interface on the base table being inserted InsertRow insert method.
insert into mysybase.pubs2.dbo.test values ('923111') for example.

Declare statements.
DECLARE @sqlstatement nvarchar(1000), @parameters nvarchar(255)
SET @sqlstatement = N'SELECT * FROM mysybase.pubs2.dbo.publishers WHERE
pub_id > @1389'
SET @parameters = N'@1389 int'
EXEC sp_executesql @sqlstatement, @parameters, @1389 = 0877

Here is a simple select statement


Select [au_id],[au_lname],[au_fname],[phone],[address],[city]
,[state], [country], [postalcode]
FROM [MYSYBASE].[pubs2].[dbo] [authors]
You can also write it like this.
Select au_id,ua_lname,au_fname,phone,address,city.state.country,postalcode
From MYSYBASE.pubs2.dbo.authors
You can omit the brackets [] from the statement, just keep the format uniform.
Fig7

In this example we are inserting data see Fig8.


INSERT INTO [MYSYBASE].[pubs2].[dbo] [authors]
([au_id],[au_lname],[au_fname],[phone],[address],[city]
,[state], [country], [postalcode])
VALUES
(‘498-52-8567’,‘Walrod’,‘Kevin’,‘123-452-9876’,‘Moon Ave’,
‘Boston’,‘MA’,‘USA’,‘01988’)
Fig8
Now let do a simple delete Statement.
DELETE FROM [MYSYBASE].[pubs2].[dbo].[authors]
WHERE au_id =’498-52-8567’ See Fig9

Another way of writing the same statement is.


DELETE FROM MYSYBASE.pubs2.dbo.authors
WHERE au_id =’498-52-8567’

Fig 9
Here is an execute statement example.
Exec (‘select * from authors where au_fname = “ANN”’) AT MYSYBASE

You can also do it this way by using openquery:

Select * from openquery (mysybase,’ select * from authors where au_fname = “ANN” ’)
See Fig 10
Fig 10

Errors:
If you get error Msg 7302 this can be caused by not having the Schema updated.
It can also mean there is bad connection information such as Product Name.
Or Msg 7302, Level 16, State 1, Line 1 Cannot create an instance of OLE DB provider
"ASEOLEDB" for linked server "MSSYBASE". This Error is a permission error. The
user account is not on or does not have permission on the remote Operating System. Go
thru the DCOM steps and make sure your domain account is properly added to
the local host where MS-SQL is running. Or your local account has permission in
DCOM. If you get an error 7311 please read http://support.microsoft.com/kb/906954
Issue:
Setting the InProc is an issue with the Sybase ASE OLE DB provider. Engineering is
working on a fix for this. Also you need to make sure you “Enable Dynamic Prepare”.
I have found Security is the biggest issue when using link Server. Again, DCOM
configuration is very important, so make sure you formulizes yourself with the
configuration options.

Limitation
First there are limitations in place on the Link Server 2005 by Microsoft. For example,
READTEXT, WRITETEXT, and UPDATETEXT statements are not supported
against remote tables. Data definition language statements such as CREATE, ALTER,
or DROP statements are not allowed against linked servers. NULL constants cannot be
inserted into a timestamp column through a distributed query. $IDENTITY and
$ROWGUIDCOL are not supported with distributed queries. Explicit values cannot be
inserted into identity columns in remote tables.

Conclusion.
The ASE OLE DB Provider (32 bit and 64 bit) by Sybase, also known as the “organic
drivers”, are high performance and powerful providers. Sybase Engineering has made
major commitments to the improvements in the drivers in several key areas: performance,
link Server, SSIS and Replication. Sybase Engineering has added new feature into the
driver, inserting into a table with float or nchar columns via link server, support for four
part naming convention and several others. The OLE DB Provider is now compatible
with link Server 2005 32 bit and 64 bit. As the provider matures, Sybase Engineering will
keep refining the divers to meet the demands of our customers. With that being said,
using the Sybase ASE OLE DB Provider with Microsoft link Server 2005 will make
configuration that much easier to use with Sybase ASE.

You might also like