when I view this odbcinst -j
it shows
unixODBC 2.2.14
DRIVERS............: /etc/unixODBC/odbcinst.ini
SYSTEM DATA SOURCES: /etc/unixODBC/odbc.ini
FILE DATA SOURCES..: /etc/unixODBC/ODBCDataSources
USER DATA SOURCES..: /etc/unixODBC/odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
But there is no location /etc/unixODBC/odbcinst.ini
. The actual location is /etc/odbcinst.ini
so I need to change the location. How can I do it?
I'm trying to run below script
import pyodbc
cnxn = pyodbc.connect('DRIVER={SQLServer};SERVER=10.10.10.1;DATABASE=ABC;UID=username;PWD=password')
cursor = cnxn.cursor()
But it shows the following error
pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnect)')
and I added the odbc.in and odbcinst.ini file information as follows
cat odbc.ini
[SQLServer]
Description = ODBC for MSSQL
Driver = /usr/lib/x86_64-linux-gnu/odbc/libodbcmyS.so
Servername =
Database =
UID =
Port = 1433
cat /etc/odbcinst.ini
[SQLServer]
Description = ODBC for MSSQL
Driver = /usr/lib/x86_64-linux-gnu/odbc/libodbcmyS.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so
UsageCount = 1
FileUsage = 1
I hope the problem is in odbcinst -j
when I show it it displays the wrong path. I don't know how to fix.?
Go to [Cognos_BI_InstallDir] /etl/odbc/ directory and edit the odbcinst. ini file to make sure that the string value of the Driver parameter is the path of [Cognos_BI_InstallDir] /etl/odbc/libratlxml.so file. In the odbc.
INI. 64-bit SYSTEM ODBC data sources are stored in the registry under HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC. INI. 32-bit SYSTEM ODBC data sources are stored in the registry under HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBC.
The system file odbcinst. ini contains information about ODBC drivers available to all users, and the odbc. ini file contains information about DSN's available to all users.
ODBC data sources are stored in the Windows registy. System ODBC data sources are stored in HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC. INI .
It looks like the "default" path is not set correctly.
I'm pretty sure you're already doing it as it is mentioned in different places, but I want to remind that you should set the right environmental variables as described in the following links:
http://www.raosoft.com/ezsurvey/help/2007/odbc_in_unix.html
http://gemfirexd.docs.pivotal.io/1.3.0/userguide/developers_guide/topics/odbc/install_config_odbc.html
It means that in your case, you could add a couple of lines to your .bashrc
or .bash_profile
or similar so that the program points to the right locations every time you would open your shell.
The lines to add would be then:
export ODBCINI=/etc/odbc.ini
export ODBCSYSINI=/etc
Looking indeed at the source code of unixODBC-2.2.14-p2 package, when invoking odbcinst -j
it will go through the following branch in the code
case 'j':
PrintConfigInfo();
exit(0);
and PrintConfigInfo()
will do the job of printing a bunch of info, specifically what you see
void PrintConfigInfo()
{
char szFileName[ODBC_FILENAME_MAX+1];
char b1[ 256 ], b2[ 256 ];
printf( "unixODBC " VERSION "\n" );
*szFileName = '\0';
sprintf( szFileName, "%s/odbcinst.ini", odbcinst_system_file_path( b1 ), odbcinst_system_file_name( b2 ));
printf( "DRIVERS............: %s\n", szFileName );
*szFileName = '\0';
_odbcinst_SystemINI( szFileName, FALSE );
printf( "SYSTEM DATA SOURCES: %s\n", szFileName );
*szFileName = '\0';
_odbcinst_FileINI( szFileName );
printf( "FILE DATA SOURCES..: %s\n", szFileName );
*szFileName = '\0';
_odbcinst_UserINI( szFileName, FALSE );
printf( "USER DATA SOURCES..: %s\n", szFileName );
printf( "SQLULEN Size.......: %d\n", sizeof( SQLULEN ));
printf( "SQLLEN Size........: %d\n", sizeof( SQLLEN ));
printf( "SQLSETPOSIROW Size.: %d\n", sizeof( SQLSETPOSIROW ));
}
Now let's examine one of the print statements to understand where it gets the path from, let's take for example the line
printf( "SYSTEM DATA SOURCES: %s\n", szFileName );
where szFileName
is set by the following call:
_odbcinst_SystemINI( szFileName, FALSE );
which is defined in the file odbcinst/_odbcinst_SystemINI.c
:
BOOL _odbcinst_SystemINI( char *pszFileName, BOOL bVerify )
{
FILE *hFile;
char b1[ 256 ];
sprintf( pszFileName, "%s/odbc.ini", odbcinst_system_file_path( b1 ));
if ( bVerify )
{
/* try opening for read */
hFile = uo_fopen( pszFileName, "r" );
if ( hFile )
uo_fclose( hFile );
else
{
/* does not exist so try creating it */
hFile = uo_fopen( pszFileName, "w" );
if ( hFile )
uo_fclose( hFile );
else
return FALSE;
}
}
return TRUE;
}
where it sets the string to be printed in the following line
sprintf( pszFileName, "%s/odbc.ini", odbcinst_system_file_path( b1 ));
To understand how odbcinst_system_file_path( b1 )
sets this path we look at the source and one finds
char *odbcinst_system_file_path( char *buffer )
{
char *path;
static char save_path[ 512 ];
static int saved = 0;
if ( saved ) {
return save_path;
}
if (( path = getenv( "ODBCSYSINI" ))) {
strcpy( buffer, path );
strcpy( save_path, buffer );
saved = 1;
return buffer;
}
#ifdef SYSTEM_FILE_PATH
else {
strcpy( save_path, SYSTEM_FILE_PATH );
saved = 1;
return SYSTEM_FILE_PATH;
}
#else
else {
strcpy( save_path, "/etc" );
saved = 1;
return "/etc";
}
#endif
}
which as you can see read the environmental variable through getenv( "ODBCSYSINI" )
. Similar for others. Now, the original code has another branch but ends up doing a similar thing using customized functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With