ds_provider_microsoft_py_lib.linked_service

File: __init__.py Region: ds-provider-microsoft-py-lib/linked_service

Linked service module for Microsoft provider.

Example: >>> linked_service = MsSqlLinkedService( … settings=MsSqlLinkedServiceSettings( … server=”account name”, … database=”database”, … username=”username”, … password=”password”, … ), … id=uuid.uuid4(), … name=”testmssqlpackage”, … version=”0.0.1”, … description=”testmssqlpackage” … ) >>> linked_service.connect()

Submodules

Classes

MsSqlLinkedService

Linked service for connecting to Microsoft SQL Server.

MsSqlLinkedServiceSettings

The object containing the Microsoft SQL Server linked service settings.

Package Contents

class ds_provider_microsoft_py_lib.linked_service.MsSqlLinkedService[source]

Bases: ds_resource_plugin_py_lib.common.resource.linked_service.LinkedService[MsSqlLinkedServiceSettingsType], Generic[MsSqlLinkedServiceSettingsType]

Linked service for connecting to Microsoft SQL Server.

This linked service manages connections to SQL Server databases. It handles authentication, connection lifecycle, and error handling according to the linked service contract.

Example

>>> settings = MsSqlLinkedServiceSettings(
...     server="localhost",
...     database="mydb",
...     username="user",
...     password="pass"
... )
>>> service = MsSqlLinkedService(
...     settings=settings,
...     id=uuid.uuid4(),
...     name="my_mssql",
...     version="0.0.1"
... )
>>> service.connect()
>>> with service as svc:
...     data = svc.connection.execute(...)
settings: MsSqlLinkedServiceSettingsType
_connection: sqlalchemy.engine.Engine | None = None

The SQLAlchemy Engine instance representing the connection to the SQL Server database.

check_settings_is_set() None[source]

Check if settings are set correctly.

Returns:

None

Raises:

AttributeError – If settings are not set correctly.

property connection: sqlalchemy.engine.Engine

Get the backend connection (SQLAlchemy Engine).

Returns:

The SQLAlchemy Engine instance.

Return type:

Engine

Raises:

ConnectionError – If connect() has not been called.

property type: ds_provider_microsoft_py_lib.enums.ResourceType

Get the type of the linked service.

Returns:

ResourceType

_get_connection_string() str[source]

Build the ODBC connection string.

Returns:

The ODBC connection string.

Return type:

str

_create_engine() sqlalchemy.engine.Engine[source]

Connect to SQL Server and return SQLAlchemy Engine.

Returns:

The SQLAlchemy Engine instance.

Return type:

Engine

Raises:
  • ConnectionError – If the engine cannot be created.

  • AuthenticationError – If credentials are invalid.

connect() None[source]

Establish a connection to Microsoft SQL Server.

The result is stored internally and accessible via the connection property.

Returns:

None

Raises:
  • ConnectionError – If the connection cannot be established.

  • AuthenticationError – If credentials are invalid.

Rules:
  • Idempotent: Calling connect() on an already-connected service reuses the connection.

  • Must authenticate using credentials from self.settings.

  • Must fail loudly if connection cannot be established.

test_connection() tuple[bool, str][source]

Verify that the connection to Microsoft SQL Server is healthy.

Performs a lightweight check against the backend (a simple SELECT 1 query). This method does not raise on connection failure – instead returns (False, “error message”). Exceptions are reserved for unexpected internal errors.

Returns:

(True, “”). On failure: (False, “reason”).

Return type:

tuple[bool, str] – On success

Rules:
  • Must not raise on connection failure.

  • Must not modify any data.

  • Should complete quickly.

  • Idempotent: Yes.

close() None[source]

Release connections, sessions, or handles held by the linked service.

This method is safe to call multiple times and does not raise even if the connection is already closed. Called automatically by __exit__ when using a context manager.

Returns:

None

Rules:
  • Must release any open connections, sessions, or handles.

  • Must not raise if the connection is already closed.

  • Must be safe to call multiple times.

  • Idempotent: Yes.

class ds_provider_microsoft_py_lib.linked_service.MsSqlLinkedServiceSettings[source]

Bases: ds_resource_plugin_py_lib.common.resource.linked_service.LinkedServiceSettings

The object containing the Microsoft SQL Server linked service settings.

server: str

The hostname or IP address of the SQL Server instance.

database: str

The name of the database to connect to.

username: str

The username for authentication.

password: str

The password for authentication. This field is masked in logs and serialized output.

port: int = 1433

The port number for the SQL Server instance. Defaults to 1433, the standard port for SQL Server.

driver: str = 'ODBC Driver 18 for SQL Server'

The ODBC driver to use for the connection. Defaults to “ODBC Driver 18 for SQL Server”

encrypt: bool = True

Whether to encrypt the connection. Defaults to True.

trust_server_certificate: bool = False

Whether to trust the server certificate when encrypting. Defaults to False.

connection_timeout: int = 30

The connection timeout in seconds. Defaults to 30.