Getting a Property

Because all SQL-DMO property values are read-only or read-write, you can get all property values.

Visual Basic

To get a property, use the following syntax:

[Set] variable = Object.Property

For example, to get a long property:

Dim lTime As Long
lTime = oSQLServer.LoginTimeout

For example, to get a string property:

Dim strHost As String
strHost = oSQLServer.HostName

For example, to get an object property:

Dim oConfiguration As SQLOLE.Configuration
Set oConfiguration = oSQLServer.Configuration

You can also use the Object.Property value directly as part of a more complex expression.

C++

For a property named Property, you use a function named GetProperty to get a property value. Because all SQL-DMO functions return an HRESULT, you must pass the address of a program variable (use the address of & operator) of the appropriate type to the GetProperty function. The GetProperty function will write the current property value to your program variable. Use the following syntax:

pObject->GetProperty ( &variable );

For example, to get a long property:

LONG lTime;
pSQLServer->GetLoginTimeout (&lTime);

Getting a string property requires an extra step. A GetProperty function for a string property takes a parameter of type SQLOLE_LPBSTR, which is the address of a SQLOLE_BSTR variable. You pass the address of a SQLOLE_BSTR variable to the GetProperty function. The GetProperty function will allocate a new string and then write the current property value to the newly allocated string. After your program is finished using the string (allocated by SQL-DMO) it must call SQLOLEFreeString macro to deallocate the string.

For example, to get a string property:

SQLOLE_BSTR strHost;
pSQLServer->GetVersionString (&strHost);
// use strHost
SQLOLEFreeString (strHost);

SQLOLEFreeString is mapped to the OLE SysFreeString function, with an appropriate conversion for ANSI strings when you are using the SQL-DMO ANSI interfaces.

For example, to get an object property:

LPSQLOLECONFIGURATION pConfiguration = NULL;
hr = pSQLServer->GetConfiguration (&pConfiguration);