Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the ODBC driver name for a connection string?

Whenever I use ODBC drivers with a full connection string, and not just a DSN entry, I often get an error similar to this

Data source name not found and no default driver specified

I have the correct syntax of the connection string (or so the Internet says), but I suspect I don't know the correct name for the current version of the ODBC driver I am using

How do I find the correct name, for either 32 or 64 bit?

like image 399
TFD Avatar asked Jan 08 '23 07:01

TFD


2 Answers

Use the ODBC Data Source Administrator app. Make sure you use the 32 bit or the 64 bit version depending on your applications build target. Then select the "File DSN" tab

ODBC Data Source Administrator

Click the "Add" button, and select the driver you have installed

"Add" button

Then click the "Advanced" button

"Advanced" button

You can then copy and paste the correct driver name, and cancel out of the ODBC Data Source Administrator app

e.g.

DRIVER={PostgreSQL ODBC Driver(UNICODE)}

Add the rest of the parameters required, and you will have a working ODBC connection string for the currently installed version of the driver

e.g.

Driver={PostgreSQL ODBC Driver(UNICODE)};Server=ruru.nz;Port=5432;Database=TheInternet;Uid=tfd;Pwd=p455w0rd;

Enjoy :-)

like image 118
TFD Avatar answered Jan 14 '23 21:01

TFD


Get-OdbcDsn -Name "[dsn-name]" -DsnType "[system|user|file]" -Platform "64-bit"

You can use powershell to get it as well. And possibly build the full connection string.

$dsn = Get-OdbcDsn -Name "dsn-plus" -DsnType "user" -Platform "64-bit"
$dsn
$dsn.DriverName
#$dsn.Attribute

$connecton_string = 'driver="' + $dsn.DriverName + '";'
foreach ($key in $dsn.Attribute.Keys) {
    if ([string]::IsNullOrWhiteSpace($dsn.Attribute[$key])) {
        $connecton_string = $connecton_string + $key + ";";
    } else {
        $connecton_string = $connecton_string + $key + "=" + $dsn.Attribute[$key] + ";";
    }
}

$connecton_string
like image 42
TamusJRoyce Avatar answered Jan 14 '23 22:01

TamusJRoyce