Applied Information Sciences UniAccess WHITE PAPERS LAST UPDATED: May 31, 2005 Using Microsoft SQL Server with UniAccess This paper discusses methods of using UniAccess with Microsoft SQL Server. The paper covers two topics: Calling UniAccess Using Microsoft SQL Server Distributed Queries, and Using UniAccess to Replicate Microsoft SQL Server Data to RDMS 2200. Calling UniAccess Using Microsoft SQL Server Distributed Queries This section defines how to call UniAccess using Microsoft SQL Server’s Distributed Query feature. There are four methods that can be used to access RDMS databases: Four-part names, OPENQUERY, OPENROWSET, and, beginning with SQL Server 2000, OPENDATASOURCE. Using the four-part names and OPENQUERY methods, the UniAccess server must first be configured as a Linked Server under SQL Server. Then distributed queries can be made against UniAccess ODBC Server for OS 2200 and/or UniAccess Transaction Server for OS 2200. Configuring UniAccess as a Microsoft SQL Server Linked Server Microsoft SQL Server linked servers are OLE DB data sources that can be referenced using fourpart names in distributed queries. 1. Using the ODBC Data Source Administrator, create a System DSN using UADriver. This is the UniAccess server for which you will create a Microsoft SQL Server Linked Server. Test the connection using the Test tab in the UniAccess configuration dialog. 2. Using the SQL Server Enterprise Manager (depicted in Figure 1), expand a server group, expand a server, and then expand Security. 3. Right-click Linked Servers; then click New Linked Server. The Linked Server Properties — New Linked Server dialog will open. 4. On the General tab, specify the name of the server to add as a linked server. This will be the name that is used from T-SQL. It can be, but need not be, the same as the DSN created in step 1. 5. Under Server Type, select Other data source. 6. Under Provider Name, select Microsoft OLE DB Provider for ODBC Drivers. 7. There are several options for the next step. The approach taken will be dictated by the type of security desired. The following is one of the options as depicted in Figure 2, Figure 3, and Figure 4: a. Under the Provider String option specify a connection string as follows: DSN=uasystemdsn;UID=userid;PWD=password where: uasystemdsn is the System DSN created in step 1 above. userid is a valid OS 2200 userid. password (optional) is a valid OS 2200 password. This is (required if TIP session control is active, otherwise, leave blank). b. Under the Security Tab, select Be made without using a security context. c. Use the Linked Server Options tab to view or set the values for the various options. d. Close the Linked Server Properties dialog. The new linked server should appear under Linked Servers in the SQL Server Enterprise Manager window (as depicted in Figure 5). 8. If you wish to run a SQL Server select query using four-part names against the linked server, you must configure your UniAccess DSN to support the owner field. To accomplish this, go into the UADriver Setup for your particular DSN, select the Advanced tab, and set Workarounds to 32 (see Figure 6). Applied Information Sciences 2 Figure 1: SQL Server Enterprise Manager Applied Information Sciences 3 Figure 2: Linked Server Properties Dialog — General Applied Information Sciences 4 Figure 3: Linked Server Properties Dialog — Security Applied Information Sciences 5 Figure 4: Linked Server Properties Dialog — Server Options Applied Information Sciences 6 Figure 5: SQL Server Enterprise Manager Showing New UniAccess Linked Server Applied Information Sciences 7 Accessing RDMS 2200 Databases Using Microsoft SQL Server’s Distributed Query Feature RDMS 2200 databases can be accessed indirectly through Microsoft SQL Server using OPENQUERY, four-part names, OPENROWSET, and OPENDATASOURCE methods as T-SQL statements. The OPENQUERY and four-part names statement require a linked server be configured as described above. The OPENROWSET and OPENDATASOURCE methods, also known as ad hoc queries, do not require a linked server. All these methods provide read-only access (SQL SELECT) to RDMS data. In order to update RDMS data, we recommend using distributed query to call RPCs, discussed at the end of this section. Note: The root cause of update statements not working is that SQL Server (OLE DB/ADO) is attempting to retrieve information about each of the columns in the insert list via SQLColAttributes. For example, a call is made to SQLColAttributes to obtain the owner of the column. The owner information is not available as a column attribute. UADriver cannot return the owner information on a column basis via SQLColAttributes, since the only information available regarding a column is that returned by RDMS via DECLARE ... CURSOR ... WITH DESCRIPTION. Furthermore, it is limited by the TDS, which does not send the qualifier (a.k.a. RDMS schema), nor table name. If the update statements could be submitted using four-part names, performance would likely be unacceptable. When updating data on a linked server using four-part names, SQL Server will retrieve all of the data in the table (or set of tables), descriptive information about each column, and then submit the update statement. For additional information, please see the Microsoft Knowledge Base article "PRB: Slow DELETE or UPDATE Against Non-SQL Linked Server" http://support.microsoft.com/default.aspx?scid=kb;en-us;309182. Accessing RDMS 2200 Databases Using Microsoft SQL Server’s OPENQUERY The OPENQUERY function accepts two parameters: the name of the linked server and the text of the query to pass. The format of a SQL select statement using OPENQUERY is as follows: <SQL select statement> FROM OPENQUERY (linkedserver.<select statement>[database].[owner].table where: linkedserver is the name of the linked server specified in step 4 of Configuring UniAccess as a Microsoft SQL Server Linked Server above. Note: The DSN associated with this linked server must be configured with Workarounds = 32. (Note: Expanding the table view Applied Information Sciences 8 under the Linked Servers in the SQL Server Enterprise Manager will display the owner under the Schema column.) database (optional) is the name of the database. This field must be present if using a nondefault database. owner (optional) is the name of the database owner or, if unowned, the values "PUBLIC" or [PUBLIC]. If this field is present, workarounds must be set to 32. table is the name of the table. The following examples show SQL select statements using a OPENQUERY: SELECT a.* FROM OPENQUERY (LINK2UNIACCESS, 'select * from UASAMPLE.SECOFFUSERID.employee') as a SELECT a.* FROM OPENQUERY (LINK2UNIACCESS, 'select last_name from..employee') as a A more complex OPENQUERY statement demonstrates the ability to merge data from separate servers: SELECT distinct * FROM OPENQUERY(LINK2UNIACCESS, 'select * from UNIACCESS.. EMPLOYEE') a, SQLSERVERDATABASE..SQLSERVERTABLE b where a.column1 = b.column1 Accessing RDMS 2200 Databases Using Microsoft SQL Server’s Four-Part Names The format of a SQL select statement using four-part names is as follows: <SQL select statement> FROM linkedserver.[database].[owner].table where: linkedserver is the name of the linked server specified in step 4 of Configuring UniAccess as a Microsoft SQL Server Linked Server above. Note: The DSN associated with this linked server must be configured with Workarounds = 32. database (optional) is the name of the database. This field must be present if using a nondefault database. owner (optional) is the name of the database owner or, if unowned, the values "PUBLIC" or [PUBLIC]. If this field is present, workarounds must be set to 32. (Note: Expanding the table view under the Linked Servers in the SQL Server Enterprise Manager will display the owner under the Schema column.) table is the name of the table. The following examples show SQL select statements using four-part names: Applied Information Sciences 9 SELECT * FROM LINK2UNIACCESS.UASAMPLE.SECOFFUSERID.EMPLOYEE SELECT * FROM LINK2UNIACCESS.UASAMPLE."PUBLIC".EMPLOYEE SELECT LAST_NAME FROM LINK2UNIACCESS..EMPLOYEE Accessing RDMS 2200 Databases Using Microsoft SQL Server’s OPENROWSET The OPENROWSET statement can be used without a linked server because the entire connection string can be supplied right in the OPENROWSET statement. The format of a SQL select statement using OPENROWSET is as follows: <SQL select statement> FROM OPENROWSET (‘MSDASQL’, DRIVER=dsn;HOST=host;PORT=port;UID=userid;PWD=password’,<select statement FROM database..table) where: dsn is the UniAccess datasource. host is the name or the i.p. address of the host. port is the port number for the UniAccess server. userid is the userid used to log in to the UniAccess server. password is the password to log in to the UniAccess server (required if TIP session control is active, otherwise, leave blank). The following is an example of a SQL select statement using OPENROWSET: select a.* from openrowset('MSDASQL','Driver={UniAccess};host=10.1.1.16;port=2050;uid=bluefish; pwd=111111', 'Select * from uasample.employee') as a Accessing RDMS 2200 Databases Using Microsoft SQL Server’s OPENDATASOURCE The OPENDATASOURCE statement, introduced with SQL Server 2000, Provides ad hoc connection information as part of a four-part object name without using a linked server name. The format of a SQL statement using OPENROWSET is as follows: <SQL select statement> FROM OPENDATASOURCE (‘MSDASQL’, Applied Information Sciences 10 DSN=dsn;UID=userid;PWD=password’) where: dsn is the UniAccess datasource. userid is the userid used to log in to the UniAccess server. password is the password to log in to the UniAccess server (required if TIP session control is active, otherwise, leave blank). The following is an example of a SQL select statement using the OPENROWSET method: SELECT * FROM OPENDATASOURCE ('MSDASQL', 'dsn=uacsdsn;UID=bluefish;PWD=111111'). UASAMPLE.SECOFFUSERID.EMPLOYEE Applied Information Sciences 11 Calling UniAccess RPCs using Microsoft SQL Server’s Distributed Query Feature Due to compatibility differences between SQL Server and RDMS, SQL UPDATE, INSERT, and DELETE statements will not work using any of the above referenced methods. We suggest using a UniAccess Server-Library transaction to update the RDMS data – either a user-written transaction or UARS. The format of calling a user-written RPC is as follows: linkedserver.database..rpcname <parameterlist> where: linkedserver is the name of the linked server specified in step 4 of Configuring UniAccess as a Microsoft SQL Server Linked Server above. rpcname is the name of the user-written UASL Transaction parameterlist (optional) is the RPC parameter list. The following is an example of calling a user-written UASL Transaction using a linked server: LINK2UNIACCESS.UASAMPLE..get_employee @first_name='R%', @last_name='%' The format of a SQL statement calling the language transaction (UARS) is as follows: Linkedserver[.database]..UARS ‘<SQL Statement>’ where: linkedserver is the name of the linked server specified in step 4 of Configuring UniAccess as a Microsoft SQL Server Linked Server above. database (optional) is the name of the database in which the stored procedure is located. This is only necessary if UARS is being called in a non-default database. UARS is the name of the language transaction. Following are examples of calling the language transaction (UARS) using linked servers: LINK2UNIACCESS...UARS ‘delete from employee where last_name = ‘’Doe’’’ LINK2UNIACCESS.UASAMPLE..UARS ‘select * from employee where first_name=’’Roger’’’ Applied Information Sciences 12 Using UniAccess to Replicate Microsoft SQL Server Data to RDMS 2200 Microsoft SQL Server version 6.5 and later have the capability to replicate data to ODBC data sources. The following diagram represents the flow of data from two Microsoft SQL Server databases to an RDMS 2200 database using UniAccess as the conduit. Typical uses for this type of application would be the accumulation of remote office data into a corporate-wide data warehouse running under RDMS 2200. Attributes such as the frequency of replication, the size of the commit batches, and synchronization strategies can all be configured using this architecture. Figure 6: Replicating SQL Server and UniAccess To configure SQL Server and UniAccess for replication, perform the following steps: 1. If the SQL Server is not configured for publishing, use the SQL Server Enterprise Manager to configure the server for publishing. Highlight the appropriate SQL Server, select Tools/Replication/Configure Publishing, Subscribers, and Distributors, which will start a wizard to guide you through the process. 2. Install the 32-bit UADriver. Create a system DSN for the UniAccess ODBC data source. The DSN must be configured with the following options: Applied Information Sciences 13 Tab Setting Value Contents UARS Support Manual Commit Yes UARS Convert Varchar to Char Yes UARS Storage Area Selected UARS Support SQL Server Replication Yes Advanced Support Distributed Transactions n/a Only required if immediate updating is desired. This is a radio button; therefore, it is selected with no value. Advanced UADTC Location Yes Only required if immediate updating is desired. The storage area must be created prior to attempting replication. Failure to provide a storage area will result in replication failing. Note: The userid that is used for replication must be allowed to set the above configuration items. This can be verified by running the test available under the Test tab of UADriver. 3. To create a publication for replication, use the SQL Server Enterprise Manager: a. Select the Tools/Replication/Create and Manage Publications menu item, which opens a dialog. Click the Create Publication . . . button which starts the Create Publication Wizard. Click Next. b. On the Choose Publication Database page, select the database you wish to replicate and click the Next button. On the Select Publication Type page, select the publication type. Click Next. c. On the Specify Subscriber Types page, the response is dependent upon the version of SQL Server. Select Heterogeneous data sources . . . . Multiple types of servers can be selected. Click Next. d. On the Specify Articles page, select the tables to be replicated. Click Next.. e. On the Select Publication Name and Description page, select a name and, optionally, a description. Click Next. f. On the Customize the Properties of the Publication page, make a selection. Click Next. If you have chosen to customize the properties, additional pages will be displayed. Applied Information Sciences 14 g. On the Completing the Create Publication Wizard page, click Finish. 4. To verify the properties of the publication agent using the SQL Server Enterprise Manager: a. Under the appropriate server, expand the Replication Monitor folder and the Agents folder. b. In the Snapshot Agents folder, highlight the publication. Right click on the publication and select Agent Properties . . . . c. Set the appropriate values and click OK. If no values are changed, click Cancel. 5. To start the publication agent using the SQL Server Enterprise Manager: a. Under the appropriate server, expand the Replication Monitor folder and the Agents folder. b. In the Snapshot Agents folder, highlight the publication. Right click on your selected publication in the right panel and select Start Agent (see Figure 6). 6. To configure your DSN as a subscriber using the SQL Enterprise Manager: a. Select the Tools/Replication/Configure Publishing, Subscribers, and Distribution . . menu item, which opens a dialog. b. Click on the Subscribers tab and the New button. c. Select ODBC data source and OK. d. Select your DSN, fill in the login information if needed and click OK. 7. To push the subscription to your DSN using the SQL Enterprise Manager: a. Under the appropriate server, select the Tools/Replication/Push Subscriptions to Others . . . menu item. b. Highlight the selected publication and select Push New Subscription . . . . This will start the Push Subscription Wizard. Click Next. c. On the Choose Subscribers page, select the subscriber associated with your DSN and click Next. d. On the Chose Destination Database page, either accept the default name or provide an RDMS database name. Click Next. Applied Information Sciences 15 e. On the Set Distribution Agent Schedule page, make your selections and click Next. f. On the Initialize Subscription page, make your selections and click Next. g. On the Start Required Services page, make your selections and click Next. h. On the Completing the Push Subscription Wizard page, verify your selections and click Finish. 8. To start the Snapshot agent using the SQL Enterprise Manager: a. Expand Replication Monitor/Agents and select Snapshot Agents. b. In the right panel, right click on the snapshot agent and select Start Agent Start (see Figure 7). 9. To start the Distribution Agent using the SQL Enterprise Manager: a. Expand Replication Monitor/Agents and select Distribution Agents. b. In the right panel, right click on the distribution agent and select Start Agent (see Figure 8). 10. To troubleshoot, check the status of the various agents. Applied Information Sciences 16 Figure 7: Snapshot Agent’s Result Panel Applied Information Sciences 17 Applied Information Sciences 18 DISCLAIMER Permission to use this document is granted, provided that (1) this permission, as well as the disclaimer and copyright notice that follow appear in all copies, (2) use of this document is for informational and non-commercial or personal use only, and (3) the document is not modified in any way. APPLIED INFORMATION SCIENCES, INC. AND/OR ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THE INFORMATION CONTAINED IN THIS DOCUMENT FOR ANY PURPOSE. THIS DOCUMENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. APPLIED INFORMATION SCIENCES, INC. AND/OR THEIR RESPECTIVE SUPPLIERS HEREBY DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THIS INFORMATION, INCLUDING ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL APPLIED INFORMATION SCIENCES, INC. AND/OR THEIR RESPECTIVE SUPPLIERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF INFORMATION AVAILABLE IN THIS DOCUMENT. THIS DOCUMENT COULD INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS. CHANGES ARE PERIODICALLY ADDED TO THE INFORMATION HEREIN. APPLIED INFORMATION SCIENCES, INC. AND/ OR THEIR RESPECTIVE SUPPLIERS MAY MAKE IMPROVEMENTS AND/OR CHANGES IN THE PRODUCT(S) AND/OR THE PROGRAM(S) DESCRIBED HEREIN AT ANY TIME. IN NO EVENT SHALL APPLIED INFORMATION SCIENCES, INC AND/OR ITS RESPECTIVE SUPPLIERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF SOFTWARE, DOCUMENTS, PROVISION OF OR FAILURE TO PROVIDE SERVICES, OR INFORMATION AVAILABLE FROM THIS SERVER. COPYRIGHT NOTICE. Copyright 2005 Applied Information Sciences, Inc., 1850 Centennial Park Drive, Reston, Virginia, 20191 U.S.A. All rights reserved. TRADEMARKS. Product and company names mentioned herein may be the trademarks of their respective owners. Any rights not expressly granted herein are reserved. Applied Information Sciences 19
© Copyright 2024 Paperzz