Connecting to SQL Server

Description

Alpha Anywhere AlphaDAO provides an extension driver for SQL Server to simplify building connections using any of the SQL Server ODBC drivers provided by Microsoft. You must first install the appropriate driver for the version of your SQL Server database. In the connection string dialog, select the version of the database you are connecting to. Alpha Anywhere will select the installed driver that is the best fit for the target version.

Using the SQL Server Connection String Dialog 

When you select SQL Server as your connection type in the connection string dialog, the dialog below will be displayed. Select the version of your database, enter the server name and provide any authentication information required to connect to your database. The values you select will be generated into the connection string at the top of the dialog for you as you make changes.

  • Before you begin, make sure you have installed and configured your SQL Server server and installed the appropriate client side driver. For more information on installing and configuring SQL Server, see https://www.microsoft.com/en-us/sql-server/sql-server-downloads.

    Alpha Anywhere is a 32-bit executable. You must install the 32-bit ODBC client driver for your database. To view those drivers, you will need to run the 32-bit ODBC Data Source Administrator found at c:\windows\syswow64\odbcad32.exe.

  • images/MicrosoftODBCAd32.jpg
  • If you do not install the version of the ODBC driver Microsoft recommends for your database, you may be able to connect, but you could get errors or unexpected results when executing SQL.

    The list below shows the database version and the recommended driver for that database. The version that you see in the Microsoft ODBC administrator dialog is for the client driver of that name specifically. It is independent of the database server version. You may need to update your client driver from time to time as updates are made available from Microsoft.

    Again, the client driver name is the one that you want to match the database version.

    As of this writing the following client drivers are available for the various versions of the SQL Server database.

    SQL Server Version
    Client Driver Name
    2017,2019

    ODBC Driver 17 for SQL Server

    2016

    ODBC Driver 13 for SQL Server

    2014

    ODBC Driver 11 for SQL Server

    2012

    SQL Server Native Client 11.0

    2008

    SQL Server Native Client 10.0

    2005

    SQL Native Client

    Older Versions

    SQL Server

    Consult the documentation for Microsoft SQL Server for more information about downloading and installing client drivers.

  • The SQL Server connection string dialog has tab pages for general properties, timeouts, SSH tunneling, and advanced properties. Each of the properties are described below.

    images/SQLServerConnectionStringDialogGeneral.png
    Click the Refresh button to see a list of databases, or leave the entry blank and click Test Connection. Once you have made an initial connection, you can click the Create Database button to create a new database on the server.
  • The Timeouts tab page lets you override default timeouts for login, the lifetime of the connection and for each query.

    images/SQLServerConnectionStringDialogTimeouts.png
  • The SSH tab is used to enable a connection to a database using an SSH2 tunnel. These connections are made from a local tunnel that is connected to a remote server and then finally to the actual database, typically behind a firewall. Alpha Anywhere will create and manage the tunnel for you based on the values you provide on this page.

    images/SQLServerConnectionStringDialogSSH.png
  • The Advanced tab is used to set up a secure connection, enable column encryption, enter additional parameters and provide an initial command to be executed at connect time.

    To set SQL server parameters that are not directly supported by the SQL Server connection string dialog, enter them as comma separated key=value entries. They will be passed directly to the connection string provided to SQL Server.

    To execute one or more commands immediately after connecting to the database, enter native SQL Server commands separated by a semi-colon.

    images/SQLServerConnectionStringDialogAdvanced.png

SQL Server Connection String Properties 

Connection Property
Description
A5API

Setting the connection property A5API to 'SQLServer' will load the SQL Server driver when you open a connection.

A5DBVersion

The version number of SQL Server your server is running. This will assure that your client connects using the driver best matched to your SQL Server server.

Server

Enter the DNS name or IP address of your server.

Port

SQL Server defaults to an IP address of 1433. It is a good practice to set the server port to a different value so that it is not as obvious what port SQL Server is running on. This is not a substitute for using secure connections.

UserName

Set this value to the user name you wish to connect to the database with. This is only needed if trusted_connection is not set to 'yes'

Password

Set this value to the password value you wish to connect to the database with. This is only needed if trusted_connection is not set to 'yes' Using the connection string dialog will obscure the password within the connection string. Publish functions encrypt the connection string.

Database

Enter or select the name of the database you are targeting.

A5TraceSQL

Set this value to Y to trace SQL statements. Within Alpha Anywhere messages are written to the trace pane. For Application Servers the output is written to a file. The actual location varies by server.

A5TraceSQLLevel

Set this value to determine how much detail will be written to the trace log. When set to "Errors", only errors will be reported. When set to "SQL" a summary of each statement and the results will be reported, including errors. When set to "Complete" all errors and SQL will be reported as well as key function calls and translated queries with argument markers as well as any caller context provided. When set to "Diagnostic", all of the previous output will be included along with the user thread name, the argument values and bind mappings. All other values are treated as if "SQL" was set.

A5TraceSQLFormat

Set this value to indicate the output format desired. When set to "JSON", information will be written in JSON format with a trailing comma. Parsing a file in JSON format can be done by stripping the last trailing comma and wrapping the text in square brackets "[]". When set to "Text", the output is written as formatted text. This is the default format.

A5LoginTimeout

Set this value to control the timeout for new connections in seconds. Omit this setting to use the SQL Server ODBC driver default value.

A5ConnectionTimeOut

Set this value to control the timeout for the lifetime of a connection in seconds. Omit this setting to use the SQL Server ODBC driver default value.

A5QueryTimeOut

Set this value to control the timeout for a single query in seconds. Omit this setting to use the SQL Server ODBC driver default value.

A5SSHTunnel

The conection string properties for SSH connections are discussed separately in Connecting Securely with SSH.

A5SSL

Set this value to 'Y' to encrypt connections to the server. The default value of this parameter is 'N'.

A5TrustServerCertificate

Set this value to 'Y' if you are using a self-signed certificate and do not want to check the server identity against a certificate authority. This value should never be set to 'Y' on a production server, but can be useful in testing out secure connections on a development server. The default value of this parameter is 'N'.

A5EnableColumnEncryption

Set this value to 'Y' to enable column encryption for the Always Encrypted feature of SQL Server. This will add the string "ColumnEncryption=Enabled" to the SQL Server connection string. For more information on this feature see https://docs.microsoft.com/en-us/sql/relational-databases/security/encryption/always-encrypted-database-engine. The default value of this parameter is 'N'.

A5ForceStringsToUTF

Set this value to 'Y' to disable functions that send data to the database as wide characters (16-bit Unicode). Data will instead be bound and passed as multi-byte characters. The default value of this parameter is 'N'.

A5ANSINullPadWarn

This property is obsolete.

A5InitialCommand

Set this value to the semi-colon delimited list of commands you want to execute after a connection is opened.

Using Portable SQL with SQL Server 

  • A SQL Server connection automatically selects SQL Server as it's syntax. The SQL Server syntax handler reads table information, and generates DDL (Data Definition Language) such as CREATE TABLE, DROP TABLE and DML (Data Manipulation Language) such as SELECT, INSERT, UPDATE, DELETE. It is also responsible for translating AlphaDAO Portable SQL functions into native implementations.

  • The SQL Server syntax handler may be used with the ODBC and ADO.Net drivers as well.