How do I install RODBC so that is uses unixODBC? - sql-server

After installing and configuring FreeTDS and unixODBC and confirming they are working correctly, I am trying to configure RODBC. However, I am getting the following results when attempting to view the ODBC data sources in the R console.
> odbcDataSources()
named character(0)
If I attempt to use the FreeTDS driver I get the following results.
>odbcDriverConnect("driver={FreeTDS};server=xx.xx.xx.xx;port=1433;database=XXXX_Analysis;trusted_connection=true;UID=********;PWD=********") :
[RODBC] ERROR: state IM003, code 0, message [iODBC][Driver Manager]Specified driver could not be loaded
Based on the error, it looks like RODBC is trying to use iODBC instead of unixODBC. I am not sure how to configure RODBC to use unixODBC.

The proper way to do this is to specify the odbc manager to the package's configure script, like this
install.packages("RODBC",
type = "source",
INSTALL_opts="--configure-args='--with-odbc-manager=odbc'"
)
--with-odbc-manager=odbc indicates you want to use unixODBC
--with-odbc-manager=iodbc indicates you want to use iODBC

I also had this issue after configuring unixODBC on Mac OS 10.13.3 High Sierra. I tried configuring my .Renviron to set an R-specific environment variable for ODBCINI, but RODBC still wouldn't list my data source names (DSNs). Additionally, I couldn't get it to find the driver specified in ODBCinst.ini or even get a connection string working with RODBC::ODBCDriverConnect(), despite being able to connect with isql.
What ended up working was simply:
remove.packages('RODBC')
install.packages('RODBC', type="source")
It seems if you install RODBC from source on mac, it picks up on the odbc.ini file and odbcinst.ini file correctly.
Thanks to this post's subtle comment for unlocking the key:
http://eriqande.github.io/2014/12/19/setting-up-rodbc.html

Turns out the default RODBC package install won't work with unixODBC. Here is a process for recompiling and installing RODBC.
Remove current generic RODBC package via the R console.
>remove.packages("RODBC")
Removing package from ‘/Library/Frameworks/R.framework/Versions/3.4/Resources/library’
(as ‘lib’ is unspecified)
Download the source for RODBC.
https://cran.r-project.org/src/contrib/RODBC_1.3-15.tar.gz
Set the environment variable DYLD_LIBRARY_PATH to the location where your unixODBC library is located. I used homebrew to install unixODBC so my my library is located in /usr/local/lib.
export DYLD_LIBRARY_PATH=/usr/local/lib
Now reinstall RODB so it picks up the new library location.
R CMD INSTALL /Users/xxxxxx/Downloads/RODBC_1.3-15.tar.gz
There is quite a bit of output but look towards the end and you should see something like this.
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o RODBC.so RODBC.o -lodbc -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
installing to /Library/Frameworks/R.framework/Versions/3.4/Resources/library/RODBC/libs
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (RODBC)
Notice the -L/usr/local/lib indicating the library location was picked up.
Now you should be able to see your ODBC connections provided by unixODBC. Back in the restarted R console you can type the following to verify RODBC is using unixODBC.
> library("RODBC")
> odbcDataSources()
MYMSSQL1 MYMSSQL XXXXXXXXX_C_DB XXXXXXXX-SQL1
"FreeTDS" "FreeTDS" "FreeTDS" "FreeTDS"
Thanks to hiltmon for helping put me on the right track.

Related

how to setup odbc for MSSQL SERVER correctly

i have made a QT Desktop application as an Appimage. On my development laptop it works fine connecting to the database flawless. But when i put the Appimage to my PC where also the MS SQL Server is hosted it does not work anymore.
My Laptop and PC are Linux Mint 19 Laptop is 19.1 and PC is 19.3 to be specific.
I have installed odbc and tds following this guide:
https://help.interfaceware.com/kb/904
Ubuntu
Run the following commands using a terminal window, or the CLI:
Get the latest package info:
sudo apt-get update
Install libodbc.so, libtdsS.so, isql, and isqlinst:
sudo apt-get install unixodbc
Install libtsdsodbc.so and tsql:
sudo apt-get install tdsodbc
Create a file called odbc.ini
i also edited the /etc/odbc.ini
like this:
Description = MS SQL Server Driver
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
Server = 192.168.0.10
Port = 1433
but when i run the application on the PC i always get:
QSqlError("0", "QODBC3: Unable to connect", "[unixODBC][Driver Manager]Can't open lib 'libtdsodbc.so' : file not found")
i also checked that the library is really under the specified path:
/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
yes it is really there.
so i asking what do i missing here?
help would be really appreciated
best regards
Rolf
I found the solution myself.
I tired to falsify the odbc.ini and the odbcinst.ini on my laptop trying to
reproduce the error there i found that it did took no effect.
After searching for the libtdsodbc.so on the laptop i found it also located at
/usr/local/lib/
so i copied the library from /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so to
/usr/local/lib
and that solved the issue and the QT application is now working fine.

How to install PostGIS into Postgres-XL correctly?

I have Postgres-XL 10 installed with geos-3.9.1 and postgis-3.1.1 on my Amazon Linux 2 machine. My cluster is running and working flawlessly but I am having troubles with getting postgis installed into the database. I've built and installed everything from source.
The error I'm getting when I run CREATE EXTENSION postgis; is:
ERROR: could not load library "/usr/local/pgsql/lib/postgis-3.so": libgeos_c.so.1: cannot open shared object file: No such file or directory
Using solutions from other posts online, I have tried:
Running sudo ldconfig
Using the --enable-shared option when installing geos and postgis
Ensured /usr/local/lib is in the LD_LIBRARY_PATH environment variable and I also added /usr/local/pgsql/lib to LD_LIBRARY_PATH
None of these solutions worked. I can't install PostGIS or Geos using yum because it will install postgresql 12 which conflicts with my version of postgresql which is a custom one for Postgres-XL.
Is there anything else I can try to solve this error? Any help is appreciated.
Thanks.
It looks like you might need to downgrade. Postgres-XL is only supporting 2.0.x versions of postgis right now. At least according to their docs.
https://www.postgres-xl.org/faq/
Q. Is PostGIS supported?
Yes, PostGIS can be added to Postgres-XL. It has been tested with PostGIS 2.0.

snmpd not found issue?

I've installed the net-snmp package (version 5.8) by downloading the tar.gz file and compiling the files inside on a RHEL server (version 6.9).
I can see that the package is installed when I type snmpd --version but whenever I try to use service snmpd restart it says snmpd: unrecognized service.
I did all the setups and the snmpd.conf file was created (but not at /etc/snmp/ for some reason initially, so I copied the file there) but it seems like snmpd isn't being recognized at all.
I even tried snmpd restart but nothing happens and it seems like the SNMP connection still isn't there either.
Is there a way to fix this issue? Thanks!

RODBC on macOS Catalina

I'm having trouble getting RODBC to work on macOS Catalina. I'm trying to connect to MS SQL Server. I have installed unixODBC using Homebrew and installed the Microsoft ODBC drivers from here. RODBC installs fine, and I installed it using this as suggested elsewhere:
install.packages('RODBC', type="source", configure.args='--with-odbc-include=/usr/local/lib' )
But when I run this:
RODBC::odbcDriverConnect(connection = "driver={ODBC Driver 17 for SQL Server};server=XYZ;database=XYZ;UID=XYZ;PWD=XYZ")
it hangs -- I have to cancel the command, and then I get a bunch of warnings that look like this:
[RODBC] ERROR: state IM003, code 0, message [iODBC][Driver Manager]Specified driver could not be loaded
I know that the SQL Server driver is installed, since using the ODBC package in R works -- with the same driver! But for some reason RODBC is using iODBC, and is apparently looking in the wrong place for the driver.
I'm trying to write code that will run on different platforms, and I've successfully used RODBC on Ubuntu and Windows. But I'm having a tough time figuring out how to get RODBC to work on my MacBook.
I had the same issue connecting with Impala on Mac after some upgrades. The workaround was to make sure RODBC used unixodbc instead of iODBC as follows:
install unixodbc. I used brew.
Remove RODBC with remove.packages("RODBC")
Reinstall RODBC from source and specify the path to unixodbc lib and include
with
install.packages("RODBC", type = "source", configure.args = c("--with-odbc-include=/usr/local/include/","--with-odbc-lib=/usr/local/lib/") )
On my computer unixodbc is in /usr/local

PHP 7.x connection with MSSQL server with MAMP

I am trying to connect mssql server to PHP 7.0.8 through MAMP. I have tried using freetds. On some blog people are saying to use pdo_dblib.so extension but it's not working.
Please guide me through the process of connection.
For those who still have this problem:
/Applications/MAMP/bin/php/php7.2.1/bin/pecl install sqlsrv pdo_sqlsrv
Edit php.ini:
extension=sqlsrv.so
extension=pdo_sqlsrv.so
If necessary, use brew install autoconf if you don't have it already.
While the answers posted by Vague Space and Pedro Santiago helped, I still think the answers are a bit lacking and incomplete… Or ask you to do too much. Honestly the official Microsoft instructions are overkill when they state you need to install their Docker image of SQL Server and such? C’mon… Most people just need the drivers installed to make a connection.
So here is my answer based on my experience installing the pdo_sqlsrv.so and sqlsrv.so modules in MAMP (version 5.2) but should work for most any MAMP version that supports some flavor of PHP 7.
Adjust the .bash_profile so MAMP’s binaries and libraries are a part of your $PATH settings.
First, adjust your .bash_profile so the MAMP stuff is in there; makes it easier to launch and work with MAMP specific binaries and ensures MAMP libraries are checked when doing things like installing new modules like this.
The way I like to do it is like this; set $MAMP_BIN and $MAMP_PHP variables like this and then rebuild the $PATH variables:
# MAMP stuff.
export MAMP_BIN="/Applications/MAMP/Library/bin";
export MAMP_PHP="/Applications/MAMP/bin/php/php7.2.10/bin";
# Final $PATH setting.
export PATH="/usr/local/bin:/usr/local/sbin:$MAMP_BIN:$MAMP_PHP:$PATH";
Save it and just log out of the Terminal session and back in, or just resource the .bash_profile like this:
source ~/.bash_profile
With that done, let’s install the core Microsoft ODBC binary stuff.
Install the Microsoft ODBC stuff.
Do this to install the core ODBC stuff on macOS; be sure to have Homebrew installed:
brew tap microsoft/SQLSRV-release https://github.com/Microsoft/homebrew-SQLSRV-release
brew update
brew install --no-sandbox msodbcsql17 SQLSRV-tools
Then when that’s done, go ahead and install the Unix ODBC stuff like this:
brew install unixodbc
Now install the actual PHP modules via PECL:
pecl install sqlsrv pdo_sqlsrv
With the modules installed, add them to the php.ini file in MAMP so PHP can recognize it. For PHP 7.2.10 on MAMP 5.x it should be located here:
/Applications/MAMP/bin/php/php7.2.10/conf/php.ini
And just add these config lines to the bottom of the file:
; Enable 'Microsoft Drivers for PHP for SQL Server' extension module
extension = sqlsrv.so
extension = pdo_sqlsrv.so
; Configuration
;sqlsrv.WarningsReturnAsErrors = 1
;sqlsrv.LogSeverity = 0
;sqlsrv.LogSubsystems = 0
;sqlsrv.ClientBufferMaxKBSize = 10240
;pdo_sqlsrv.log_severity = 0
;pdo_sqlsrv.client_buffer_max_kb_size = 10240
Note, most tutorials—and even PECL when you install the modules—simply mention adding extension = sqlsrv.so and extension = pdo_sqlsrv.so to the php.ini config, but these config options are the ones that RedHat has when installing the PHP SQLSRV via the Remi repo. Yeah, most of them are commented out but I still like having it there for reference.
Follow this guide through step 3: Microsoft PHP drivers for SQL Server
Find where pecl drops extensions in your local machine
Copy the files pdo_sqlsrv.so and sqlsrv.so into your MAMP's PHP extension directory. Mine was located at /Applications/MAMP/bin/php/php7x.x/lib/php/extensions/no-debug-foo-bar
Edit your php.ini file to include the new extensions:
extension=sqlsrv.so
extension=pdo_sqlsrv.so
Restart your MAMP servers.
having just done this in 2019 with MAMPPRO4 on windows 10 (follow upto step 4 to test that you are connected and then do point 9 ) point 5 onwards is for changing the path in the command line
download dll files from microsoft
https://www.microsoft.com/en-gb/download/details.aspx?id=20098
follow the instruction after running the exe file and place the dll
files into the extension directory of the php version that you are
using eg: MAMP/bin/php/php7.1.29/ext
check phpinfo for the Loaded Configuration File of the php.ini file
add the 2 dll files depending on your requirements (I wasted time by
using the 64.dll) make sure you are using ts(thread safe) not
nts(none thread safe) in the file name of the dll
extension=php_sqlsrv_71_ts_x86.dll
extension=php_pdo_sqlsrv_71_ts_x86.dll
in control panel search for advanced system settings and click
click Environment Variables
under system variables not user variables click path and click edit
click new and add C:\MAMP\bin\php\php7.1.29 (Edit this to your path)
restart MAMP
open a new command line an enter php -v
you should see the php version displayed

Resources