Connect to MSSQL via ODBC with FreeTDS - freetds

I am working with a group who needs to access a MSSQL db from a linux host and in my searching found FreeTDS, which i am able to connect with FreeTDS but our programmer states that ODBC will require to configured with FreeTDS for their PHP code to work. With that being said, i have tried configuring both unixODBC and unixODBC_23 for the past day and have been unsuccesful in finding a config that works properly and I am also not able to get tracing working either. So, without further ado, here is my config
--- odbc.ini and odbc_23.ini ---
[TC]
Description = FreeTDS Connection
Driver = FreeTDS
Database = mydb
ServerName = 192.168.1.12
TDS_Version = 7.0
PORT = 3433
[Default]
Driver = /usr/local/freetds-0.91/lib/libtdsodbc.so
---odbcinst.ini and odbcinst_23.ini---
[FreeTDS]
Description = FreeTDS
Driver = /usr/local/freetds-0.91/lib/libtdsodbc.so
Trace = 1
TraceFile = /tmp/freetds.log
UsageCount = 1
When i try connecting via isql, here is what i receive.
root#host(~)# isql_23 -v TC myuser mydb
[S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
[01000][unixODBC][FreeTDS][SQL Server]Unknown host machine name.
[ISQL]ERROR: Could not SQLConnect
root#host(~)#
Any ideas would be greatly appreciated!

Try Server instead of ServerName?
Server = 192.168.1.12

Ok, so there was one additional change that i had to make in addition to changing "ServerName" to "Server" and that was I removed "Database = mydb" and moved it to the "Server" and now my file looks like so:
[TC]
Description = FreeTDS
Driver = FreeTDS
Server = 192.168.1.12\mydb
TDS_Version = 7.0
PORT = 3433
and now im connected with this command:
root#host(~)# isql_23 -v TC user password
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL> ^C
root#host(~)#

Related

Error loading Snowflake ODBC Driver on Mac M1 from erlang call :odbc.connect

I have a problem with loading snowflake driver in the elixir application on arm64 Mac m1 (on x86 it works smoothly).
Installed:
unixodbc
erlang 24.1.2 with odbc support
snowflake driver
iODBC
ODBC manager & iODBC manager
Below is configuration of my odbc installation
➜ sandbox odbcinst -j
unixODBC 2.3.9
DRIVERS............: /usr/local/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
FILE DATA SOURCES..: /usr/local/etc/ODBCDataSources
USER DATA SOURCES..: /Users/or/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
➜ sandbox cat /usr/local/etc/odbcinst.ini
[ODBC Drivers]
SnowflakeDSIIDriver=Installed
[SnowflakeDSIIDriver]
APILevel=1
ConnectFunctions=YYY
Description=Snowflake DSII
Driver=/opt/snowflake/snowflakeodbc/lib/universal/libSnowflake.dylib
DriverODBCVer=03.52
SQLLevel=1
ODBCInstLib=/usr/local/iODBC/lib/libiodbcinst.dylib
➜ sandbox cat /opt/snowflake/snowflakeodbc/lib/universal/simba.snowflake.ini
[Driver]
ANSIENCODING=UTF-8
DriverManagerEncoding=UTF-32
DriverLocale=en-US
ErrorMessagesPath=/opt/snowflake/snowflakeodbc/ErrorMessages
LogLevel=0
LogPath=
CURLVerboseMode=false
CABundleFile=/opt/snowflake/snowflakeodbc/lib/universal/cacert.pem
ODBCInstLib=libodbcinst.dylib
➜ sandbox cat /usr/local/etc/odbc.ini
[ODBC Data Sources]
SNOWFLAKE_ODBC = SnowflakeDSIIDriver
[SNOWFLAKE_ODBC]
Driver = /opt/snowflake/snowflakeodbc/lib/universal/libSnowflake.dylib
Description = Internal Snowflake
uid = <>
server = MY_SERVER
database = <>
schema = <>
warehouse = <>
role = MY_ROLE
tracing = 6
➜ sandbox
➜ sandbox odbcinst -s -q
[SNOWFLAKE_ODBC]
➜ sandbox isql -v SNOWFLAKE_ODBC <USERNAME> <PASSWORD>
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
➜ sandbox /usr/local/iODBC/bin/iodbctest
iODBC Demonstration program
This program shows an interactive SQL processor
Driver Manager: 03.52.1521.0607
Enter ODBC connect string (? shows list):
DSN | Driver
------------------------------------------------------------------------------
SnowflakeDSII | Snowflake
Enter ODBC connect string (? shows list): SnowflakeDSII
1: SQLDriverConnect = [iODBC][Driver Manager]dlopen(/opt/snowflake/snowflakeodbc/lib/universal/libSnowflake.dylib, 6): no suitable image found. Did find:
/opt/snowflake/snowflakeodbc/lib/universal/libSnowflake.dylib: no matching architecture in universal wrapper
/opt/snowfl (0) SQLSTATE=00000
2: SQLDriverConnect = [iODBC][Driver Manager]Specified driver could not be loaded (0) SQLSTATE=IM003
I can connect via isql, iodbctest fails and my simple test case fails:
defmodule Sandbox.OdbcTest do
use Sandbox.OdbcCase
test "test odbc" do
conn_str = 'dsn=SnowflakeDSII'
IO.inspect :odbc.connect(conn_str, [])
end
end
I tried connection string as:
conn_str = 'driver=/opt/snowflake/snowflakeodbc/lib/universal/libSnowflake.dylib;server=<SERVER>;uid=<USERNAME>;pwd=<PASSWORD>;role=<ROLE>;warehouse=TEST_WH;'
➜ sandbox mix test test/odbc_test.exs
true
'driver=/opt/snowflake/snowflakeodbc/lib/universal/libSnowflake.dylib;<MY_DSN>'
{:error,
'[unixODBC][Driver Manager]Can\'t open lib \'/opt/snowflake/snowflakeodbc/lib/universal/libSnowflake.dylib\' : file not found SQLSTATE IS: 01000 Connection to database failed.'}
.
Finished in 0.05 seconds (0.00s async, 0.05s sync)
1 test, 0 failures
Randomized with seed 529170
I am afraid message from iodbstest explains everything but I hope there is solution.
I followed these articles:
https://docs.snowflake.com/en/user-guide/odbc-mac.html
https://community.snowflake.com/s/article/How-to-create-Snowflake-ODBC-DSN-On-MacOS
How do I install the ODBC driver for Snowflake successfully on an M1 Apple Silicon Mac?
ARM processor for M1 is not yet supported for ODBC drivers provided by Snowflake.
Snowflake ODBC Driver support for ARM/M1 is now available, and you can download the driver from the Snowflake Client Repository
I got a version of this working for R. You might be able to leverage a similar approach: https://stackoverflow.com/a/71790445/4319571

freeradius not load clients.conf

I am new in freeradius. I do not understand why radiusd does not take into account the clients.conf configuration file.
Extract from server logs :
-including configuration file /etc/freeradius/clients.conf
----------------------------------------------------------
--------------------
-radiusd: #### Loading Clients ####
- client localhost {
ipaddr = 127.0.0.1
require_message_authenticator = no
secret = <<< secret >>>
nas_type = "other"
proto = "*"
limit {
max_connections = 16
lifetime = 0
idle_timeout = 30
}
}
client localhost_ipv6 {
ipv6addr = ::1
require_message_authenticator = no
secret = <<< secret >>>
limit {
max_connections = 16
lifetime = 0
idle_timeout = 30
}
}
and my clients.conf in /etc/freeradius/ :
client dockernet
{
ipaddr = 172.17.0.0
secret = testing123
netmask = 24
shortname = dockernet
}
Ok , i am running freeradius with docker.
I am modifing the wrong config file
When FreeRADIUS starts up in debug mode, e.g.
radiusd -X
it prints out all the files it's reading. You need to run this to check that the file you are editing is the one actually being used.
Note that the configuration is often in different places depending on the installation.
Installed from source, the config is /usr/local/etc/raddb or /etc/raddb. On RedHat/CentOS based systems it's in /etc/raddb, and on Debian/Ubuntu systems it's in /etc/freeradius or /etc/freeradius/3.0.
For more advanced use cases, the -d option can tell FreeRADIUS to read its configuration from a different location, e.g.
radiusd -X -d /opt/raddb
This problem often comes about from having two installations, e.g. one installed from packages, and then installing from source on the same system.

Curl in vagrant to reference itself

I currently have a project running on a Ubuntu virtual machine on my computer. I am using Vagrant and Virtual Box to set up this environment and have the Puma server up and running with the command:
bundle exec puma
Which provided the following output:
Puma starting in single mode...
* Version 3.4.0 (ruby 2.3.0-p0), codename: Owl Bowl Brawl
* Min threads: 0, max threads: 16
* Environment: development
D [2016-07-04 11:26:23 $2728] DEBUG | : Register a receiver for (reschedule) queue
D [2016-07-04 11:26:25 $2728] DEBUG | : Register a receiver for (trial) queue
D [2016-07-04 11:26:25 $2728] DEBUG | : Register a receiver for (free) queue
D [2016-07-04 11:26:25 $2728] DEBUG | : Register a receiver for (renew) queue
D [2016-07-04 11:26:25 $2728] DEBUG | : Register a receiver for (renew_charge_response) queue
D [2016-07-04 11:26:25 $2728] DEBUG | : Register a receiver for (merchant_notification) queue
D [2016-07-04 11:26:25 $2728] DEBUG | : Register a receiver for (renew_charge) queue
D [2016-07-04 11:26:25 $2728] DEBUG | : Register a receiver for (partial_renew_charge) queue
* Listening on tcp://0.0.0.0:9292
Use Ctrl-C to stop
I wish to now be able to make calls to this via curl commands. At present I am able to curl to the live API which leads me to believe that my curl command is correct however when i do the same to my test environment, contained within my virtual machine I get an error referring to "Basic Auth required". From this I am assuming that I am hitting the API correctly as the error returned is one contained within the API code. My problem is Basic Authentication as I have created a user and password in my environment. I have base64 encoded this and fed the resulting string into my curl statement like below:
curl -L http://127.0.0.1:9292/v2.2/ -H "Authorization: Basic cGF5bWVudHM6cGF5bWVudHM="
For some reason it is not being accepted. Can anyway provide me with some indication as to how I could go about diagnosing the problem. Thanks in advance.
I do not believe you need to encode the password - try this:
curl --user name:password http://localhost:9292/v2.2/
just substitute your user name and password.
source:
https://curl.haxx.se/docs/httpscripting.html#Basic_Authentication
You must forward port 9292 from guest to vm. You should have something like in your Vagrantfile
config.vm.network "forwarded_port", guest: 9292, host: 9292
then you should be able to run curl command from your host machine

Why "host:localhost" must be deleted from database.yml under Cent OS 6, PostgreSQL 9.4 and Rails 3.2, or get a error: Ident authentication failed?

All config files described here are the same as my Mac OS's and all works fine in Mac OS.
I got the same error in CentOS 6 x86_64:
Ident authentication failed for user 'abelard'
When running the following two commands:
1. rake db:create
2. psql -d testforabelard2 -U abelard -h localhost
I got the same error after trying these answers 1 and 2.
My /var/lib/pgsql/9.4/pg_hba.con's content is as follows:
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
And there is a blank file /var/lib/pgsql/9.4/pg_ident.con
My database.yml's content is as follows:
development:
adapter: postgresql
encoding: unicode
database: social_stream_development
pool: 5
username: abelard
password: password
host: localhost
port: 5432
I found a resolution: the error disappear after deleting host:localhost from the above database.yml. But I can not delete host:localhost because there is a sql_host = localhost generated automatically when using think-sphinx for full-text search.
And for offering the same params as my Mac OS's, I altered PostgreSQL's user abelard :
testforabelard2=# \du
List of roles
Role name | Attributes | Member of
-----------+-------------+-----------
abelard | Superuser | {}
: Create role
: Create DB
postgres | Superuser | {}
: Create role
: Create DB
And I can run the command without -h localhost successfully:
psql -d testforabelard2 -U abelard
I don't know what things I miss, what should I do for correct this error? Any advice will be welcome!
I finally resolved myself easily through moving /var/lib/pgsql/9.4/pg_hba.con to /var/lib/pgsql/9.4/data/pg_hba.con.
The reason for this mistake I made is that I referred to my Mac OS's position of the file pg_hba.con.
Of course, I thank this early blog “FATAL: IDENT AUTHENTICATION FAILED”, OR HOW COOL IDEAS GET BAD USAGE SCHEMAS , which reminded me to realise the wrong place of the above file!

SQL Server and Rails trouble

note: this is a repost. This question was previously deleted for undisclosed reasons
Ok, I've been trying to get this to work like all day now and I'm barely any further from when I started.
I'm trying to get Ruby On Rails to connect to SQL Server. I've installed unixODBC and configured it and FreeTDS and installed just about every Ruby gem relating to ODBC that exists.
(This has been updated to show the output of isql with -v)
[earlz#earlzarch myproject]$ tsql -S AVP1 -U sa -P pass
locale is "en_US.UTF-8"
locale charset is "UTF-8"
1> quit
[earlz#earlzarch ~]$ isql -v AVP1 sa pass
[IM002][unixODBC][Driver Manager]Data source name not found, and no default driver specified
[ISQL]ERROR: Could not SQLConnect
[earlz#earlzarch myproject]$ rake db:version
(in /home/earlz/myproject)
rake aborted!
IM002 (0) [unixODBC][Driver Manager]Data source name not found, and no default driver specified
(See full trace by running task with --trace)
so, as you can see, tsql works, but not isql. What is the difference in the two that breaks it?
/etc/odbc.ini
[AVP1]
Description = ODBC connection via FreeTDS
Driver = TDS
Servername = my.server
UID = sa
PWD = pass
port = 1232
Database = mydatabase
/etc/odbcinst.ini
[TDS]
Description = v0.6 with protocol v7.0
Driver = /usr/lib/libtdsodbc.so
Setup = /usr/lib/libtdsS.so
CPTimeout =
CPReuse =
FileUsage = 1
(and yes, I've made sure that the .so files exist)
the relevant part in freetds.conf
[AVP1]
host = my.server
port = 1232
tds version = 8.0
and finally, my database.yml
development:
adapter: sqlserver
mode: odbc
dsn: AVP1
username: sa
password: pass
Can anyone please help me before I pull all my hair out?
I am using a 64 bit Arch Linux that is completely up to date.
What could be causing isql to fail. I've tried every solution I've seen so far for this problem but none of them are actually working for me. Do I have to recompile FreeTDS or something?
Ok, I have also verified with strace that it is finding the configuration file, as shown by this excerpt:
open("/etc/odbc.ini", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=159, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc71fe09000
read(3, "[AVP1]\n Description = ODBC "..., 4096) = 159
If anyone has gotten tsql to work but has searched far and wide on the Internet and has troubleshooted their configs and still has not been able to get isql to work check your server logs.
I have been troubleshooting a Xubuntu 12.04 unixodbc install and config for a week now and tried everything possible to get it fixed when I decided to check my windows server event viewer to see what was happening when the request was coming into the server or if a request was even coming into the server and discovered that the problem was that I couldn't get into a specific database. I was able to get into SQL Server ok but not the actual DB I had listed in my odbc.ini file.
Here is the specific text in the event log "Login failed for user 'ePMX'.
Reason: Failed to open the explicitly specified database. [CLIENT:
192.168.27.25]".
What sparked my interest was the word "explicit". So I simply commented out the Database = <DB Name> and suddenly everything worked and I got the SQL prompt after untold hours of researching and trying everything possible.
So if you are having trouble using unixodbc don't forget to troubleshoot the server side of things as well the client side because I have seen tons of posts where people had the exact same problem I was having but there was never any response to how to resolve it so I am guessing that a large number of the people that were having the issue were Server side issues.
For a great troubleshooting tool use osql rather than isql(osql actually in fact uses isql to connect) because it will go through the connection process step by step and give you details about where the failure occurs. It is used the same way you use isql:
osql <DSN> <user> <password>.
So as I said be sure to check your server logs if you have tried everything else and have been unable to figure out what the problem is.
Ok, I finally figured it out after only 2 straight days of banging my head against the wall.
I'll try to give as much info as possible so that if someone finds this in the same situation I was in, they'll find this useful.
[earlz#earlzarch ~]$ cat /etc/odbc.ini
[AVP1]
Description=ODBC connection via FreeTDS
Driver=/usr/lib/libtdsodbc.so
Server=192.168.0.100
UID=sa
PWD=pass
Port=1232
ReadOnly=No
[earlz#earlzarch ~]$ cat /etc/odbcinst.ini
[TDS]
Description = v0.60 with protocol v7.0
Driver = /usr/lib/libtdsodbc.so
Driver64 = /usr/lib
Setup = /usr/lib/libtdsS.so
Setup64 = /usr/lib
CPTimeout =
CPReuse =
FileUsage = 1
[earlz#earlzarch ~]$ cat /etc/freetds/freetds.conf
[global]
tds version = 8.0
initial block size = 512
swap broken dates = no
swap broken money = no
try server login = yes
try domain login = no
cross domain login = no
# If you get out-of-memory errors, it may mean that your client
# is trying to allocate a huge buffer for a TEXT field.
# Try setting 'text size' to a more reasonable limit
text size = 64512
[TDS]
host = 192.168.0.100
port = 1232
tds version = 8.0
and if your lucky, after that:
[earlz#earlzarch ~]$ isql -v AVP1
[S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
[01000][unixODBC][FreeTDS][SQL Server]Adaptive Server connection failed
[ISQL]ERROR: Could not SQLConnect
[earlz#earlzarch ~]$ isql -v AVP1 sa pass
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
I did not have to set any kind of environmental variables and I didn't have to manually compile anything either with Arch Linux 64bit (date April 7th, 2010). After getting isql to work, Rails immediately connected to the database also. Now I just have to figure out why db:schema:load isn't working, but thats another question :)
Also, notice the only real difference between this set of files and the last is in /etc/odbc.ini I set the Driver field to be the actual file name of a driver rather than named for some configuration entry.
When building FreeTDS, current versions of SQL Server need TDS protocol v8 (http://www.freetds.org/userguide/config.htm):
./configure --with-tdsver=8.0 --enable-msdblib

Resources