Connect your MS SQL database to Sitehost using ODBC

To connect your MS SQL database to Sitehost, you will need to use an ODBC connection.

If your database uses ADS account authentication, it will not work for database connections from Sitehost. Instead, you will need to use a local MS SQL username/password. You should also use the full DNS host name of the MS SQL server, and not just its ADS network name.

For security purposes, you will need to put your ODBC datasource definitions in a file in your account home directory:

/groups/<account_name>/.odbc.ini

The contents of ~/.odbc.ini should look like the following (with your database information substituted):

[<datasource_name>]

Driver = FreeTDS

Description = Microsoft SQL Server 2012 (or another version)

Server = <db_server_hostname>

Database = <database_name>

Port = 1433 (optional if using the standard port)

TDS_Version = 7.4

You can test the connection with the following code:

<?php

$user = '<db_username>';

$pass = '<db_password>';

$dsn = '<datasource_name>';

 
$dbc = odbc_connect ($dsn, $user, $pass);

 
if ($dbc) {

echo "Database Connection Successful";

odbc_close($dbc);

} else {

die("Connection could not be established");

}

?>

This is document ayxc in the Knowledge Base.
Last modified on 2023-07-18 10:39:53.