You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: "OLE Automation Objects in Transact-SQL | Microsoft Docs"
2
+
title: "OLE Automation Objects in Transact-SQL"
3
3
description: Learn how OLE Automation objects that are executed through stored procedures run in the address space of an instance of the SQL Server Database Engine.
4
4
ms.custom: ""
5
-
ms.date: "03/16/2017"
5
+
ms.date: "03/10/2022"
6
6
ms.prod: sql
7
7
ms.reviewer: ""
8
8
ms.technology: stored-procedures
@@ -12,54 +12,48 @@ helpviewer_keywords:
12
12
- "batches [SQL Server], OLE Automation"
13
13
- "OLE Automation [SQL Server]"
14
14
- "OLE Automation [SQL Server], about OLE Automation"
[!INCLUDE[tsql](../../includes/tsql-md.md)] includes several system stored procedures that allow OLE Automation objects to be referenced in [!INCLUDE[tsql](../../includes/tsql-md.md)] batches, stored procedures, and triggers. These system stored procedures run as extended stored procedures, and the OLE Automation objects that are executed through the stored procedures run in the address space of an instance of the [!INCLUDE[ssDEnoversion](../../includes/ssdenoversion-md.md)] in the same way that an extended stored procedure runs.
23
23
24
24
The OLE Automation stored procedures enable [!INCLUDE[tsql](../../includes/tsql-md.md)] batches to reference SQL-DMO objects and custom OLE Automation objects, such as objects that expose the **IDispatch** interface. A custom in-process OLE server that is created by using [!INCLUDE[msCoName](../../includes/msconame-md.md)][!INCLUDE[vbprvb](../../includes/vbprvb-md.md)] must have an error handler (specified with the **On Error GoTo** statement) for the **Class_Initialize** and **Class_Terminate** subroutines. Unhandled errors in the **Class_Initialize** and **Class_Terminate** subroutines can cause unpredictable errors, such as an access violation in an instance of the [!INCLUDE[ssDE](../../includes/ssde-md.md)]. Error handlers for other subroutines are also recommended.
25
25
26
-
The first step when using an OLE Automation object in [!INCLUDE[tsql](../../includes/tsql-md.md)] is to call the **sp_OACreate** system stored procedure to create an instance of the object in the address space of the instance of the [!INCLUDE[ssDE](../../includes/ssde-md.md)].
26
+
The first step when using an OLE Automation object in [!INCLUDE[tsql](../../includes/tsql-md.md)] is to call the `sp_OACreate` system stored procedure to create an instance of the object in the address space of the instance of the [!INCLUDE[ssDE](../../includes/ssde-md.md)].
27
27
28
28
After an instance of the object has been created, call the following stored procedures to work with the properties, methods, and error information related to the object:
29
29
30
-
-**sp_OAGetProperty** obtains the value of a property.
30
+
-`sp_OAGetProperty` obtains the value of a property.
31
31
32
-
-**sp_OASetProperty** sets the value of a property.
32
+
-`sp_OASetProperty` sets the value of a property.
33
33
34
-
-**sp_OAMethod** calls a method.
34
+
-`sp_OAMethod` calls a method.
35
35
36
-
-**sp_OAGetErrorInfo** obtains the most recent error information.
36
+
-`sp_OAGetErrorInfo` obtains the most recent error information.
37
37
38
-
When there is no more need for the object, call **sp_OADestroy** to deallocate the instance of the object created by using **sp_OACreate**.
38
+
When there is no more need for the object, call `sp_OADestroy` to deallocate the instance of the object created by using `sp_OACreate`.
39
39
40
-
OLE Automation objects return data through property values and methods. **sp_OAGetProperty** and **sp_OAMethod** return these data values in the form of a result set.
40
+
OLE Automation objects return data through property values and methods. The `sp_OAGetProperty` and `sp_OAMethod` procedures return these data values in the form of a result set.
41
41
42
42
The scope of an OLE Automation object is a batch. All references to the object must be contained in a single batch, stored procedure, or trigger.
43
43
44
44
When it references objects, the [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] OLE Automation objects support traversing the referenced object to other objects that it contains. For example, when using the SQL-DMO **SQLServer** object, references can be made to databases and tables contained on that server.
title: "OLE Automation Result Sets | Microsoft Docs"
2
+
title: "OLE Automation Result Sets"
3
3
description: Learn that if an OLE Automation property or method returns data in an array with one or two dimensions, the array is returned to the client as a result set.
If an OLE Automation property or method returns data in an array with one or two dimensions, the array is returned to the client as a result set:
25
25
26
26
- A one-dimensional array is returned to the client as a single-row result set with as many columns as there are elements in the array. For example, an array(10) is returned as a single row of 10 columns.
27
27
28
28
- A two-dimensional array is returned to the client as a result set with as many columns as there are elements in the first dimension of the array and with as many rows as there are elements in the second dimension of the array. For example, an array(2,3) is returned as 2 columns in 3 rows.
29
29
30
-
When a property return value or method return value is an array, sp_OAGetProperty or sp_OAMethod returns a result set to the client. (Method output parameters cannot be arrays.) These procedures scan all the data values in the array to determine the appropriate [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] data types and data lengths to use for each column in the result set. For a particular column, these procedures use the data type and length required to represent all data values in that column.
30
+
When a property return value or method return value is an array, `sp_OAGetProperty` or `sp_OAMethod` returns a result set to the client. (Method output parameters cannot be arrays.) These procedures scan all the data values in the array to determine the appropriate [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] data types and data lengths to use for each column in the result set. For a particular column, these procedures use the data type and length required to represent all data values in that column.
31
31
32
32
When all data values in a column share the same data type, that data type is used for the whole column. When data values in a column are different data types, the data type of the whole column is chosen based on the following table. To use the following table, find one data type along the left row axis and a second data type along the top column axis. The intersection of the row and column describes the data type of the result set column.
The OLE automation system stored procedures return an **int** return code that is the HRESULT returned by the underlying OLE automation operation. An HRESULT of 0 indicates success. A nonzero HRESULT is an OLE error code of the hexadecimal form 0x800*nnnnn*, but when returned as an **int** value in a stored procedure return code, HRESULT has the form -214*nnnnnnn*.
24
23
@@ -28,8 +27,8 @@ For example, passing an invalid object name (SQLDMO.Xyzzy) to sp_OACreate causes
28
27
29
28
You can use `CONVERT(binary(4), @hresult)` to convert an **int** HRESULT to a **binary** value.
30
29
31
-
For examples of supported conversion see [H. Using CONVERT with binary and character data](../../t-sql/functions/cast-and-convert-transact-sql.md#h-using-convert-with-binary-and-character-data).
30
+
For examples of supported conversion, see [H. Using CONVERT with binary and character data](../../t-sql/functions/cast-and-convert-transact-sql.md#h-using-convert-with-binary-and-character-data).
Copy file name to clipboardExpand all lines: docs/relational-databases/stored-procedures/ole-automation-sample-script.md
+15-21Lines changed: 15 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,24 +1,24 @@
1
1
---
2
-
title: "OLE Automation Sample Script | Microsoft Docs"
2
+
title: "OLE Automation Sample Script"
3
3
description: Learn how to use an example of a Transact-SQL statement batch that uses the OLE Automation stored procedures to create and use an SQL-DMO SQLServer object.
[!INCLUDE[SQL Server Azure SQL Database Synapse Analytics PDW ](../../includes/applies-to-version/sql-asdb-asdbmi-asa-pdw.md)]
19
-
This topic contains an example of a [!INCLUDE[tsql](../../includes/tsql-md.md)] statement batch that uses the OLE Automation stored procedures to create and use an SQL-DMO SQLServer object in the local instance of the [!INCLUDE[ssDE](../../includes/ssde-md.md)]. Parts of the code are used as examples in the reference topics for the OLE Automation system stored procedures.
This article contains an example of a [!INCLUDE[tsql](../../includes/tsql-md.md)] statement batch that uses the OLE Automation stored procedures to create and use a SQL-DMO SQLServer object in the local instance of the [!INCLUDE[ssDE](../../includes/ssde-md.md)]. Parts of the code are used as examples in the reference articles for the OLE Automation system stored procedures.
20
20
21
-
```
21
+
```sql
22
22
USE AdventureWorks2012;
23
23
GO
24
24
DECLARE @Object int;
@@ -134,17 +134,11 @@ RETURN;
134
134
GO
135
135
```
136
136
137
-
## Related Content
138
-
[OLE Automation Objects in Transact-SQL](../../relational-databases/stored-procedures/ole-automation-objects-in-transact-sql.md)
0 commit comments