Connect to Ms SQL with RODBC without dsn - sql-server

I'm trying to set up a connection from ubuntu to mssql server with the RODBC package.
I did make it work with RJDBC but read the speed might be much slower than ODBC so I wanted to test it.
I don't have a dsn available, ip port databasename usr pwd is all the information I can use.
The code used with RJDBC which works is:
drv <- JDBC("com.microsoft.sqlserver.jdbc.SQLServerDriver",
"/media/sqljdbc4.jar")
RJDBC::dbConnect(drv, 'jdbc:sqlserver://ip:port;databaseName=databasename', 'usr', 'pwd')
Tried alot around browsing different syntaxes but could not make it work.
RODBC::odbcDriverConnect('driver={SQL Server};server=ip:port;database=databasename;uid=usr;pwd=pwd)
Gives me the error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified
Do I need to download drivers to the ubuntu machine? Thought they were included with the package.

The RODBC package doesn't include drivers. That would be unwieldy given how many possibilities there are.
see https://cran.r-project.org/web/packages/RODBC/vignettes/RODBC.pdf
"connection to the particular DBMS needs an ODBC driver : these may
come with the DBMS or the ODBC driver manager or be provided
separately by the DBMS developers, and there are third-party
developers"
Microsoft provides drivers for Ubuntu:
https://www.microsoft.com/en-us/download/details.aspx?id=50419
You can add dsn entries to the /etc/odbc.ini file in most linux distros. See this for ubuntu https://help.ubuntu.com/community/ODBC

Related

Why am I getting "Data source name not found and no default driver specified" and how do I fix it?

When trying to make a program on Windows that connects to a database via ODBC, I got the following error:
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified.
I'm sure my code is right. It even worked on a different PC.
Why am I getting this error? And How do I fix it?
What causes this error?
The error message tells you, simply put, that the ODBC Driver Manager could not find the driver you specified in your connection string or DSN.
This can have 3 common causes:
The driver you tried to use is not installed on your system
The driver is installed, however, it doesn't match bitness of the code you're running
You made an error in typing the driver name
How do I check which drivers are installed on my system?
You can check the drivers which are installed on your system by going to the ODBC Data Source Administrator. To open it, press ⊞ Win + R, and type in: odbcad32.exe. Then check the tab Drivers for installed drivers. The Name column indicates the exact name you should use in your connection string or DSN.
If you're on 64-bit Windows, that only lists the 64-bit drivers installed on
your system. To see which 32-bit drivers are installed, press press ⊞ Win + R, and type in: C:\Windows\SysWOW64\odbcad32.exe, and go to the Drivers tab again.
The driver is installed, but it might be the wrong bitness, what do I do?
Then, you have two choices, either adjust the bitness your program is running in, or install a driver with a different bitness.
Some of the drivers that are installed by default on Windows only have a 32-bits variant. These can't be used with 64-bits programs.
You can usually identify which bitness a program is running under in task manager. In Windows 10, all 32-bit programs have (32-bit) appended to their name. If that isn't there, you're likely running a 64-bit program, and most modern programming languages and environments run on 64-bit by default, but allow you to switch to 32-bit. However, the specifics for different programming languages are outside the scope of this question.
How can I verify I didn't mistype the driver name?
An ODBC connection string looks like this:
DRIVER={DriverName};ParameterName1=ParameterValue1;ParameterNameN=ParameterValueN;
The driver name part needs to be delimited by curly braces if it might contain special characters, and needs to exactly match the installed driver name, as found in the ODBC Data Source Administrator, including spaces and typographical characters, but excluding capitalization.
Note that for deployed code, the driver must be present on the computer/server running the code.
I don't have the driver, or have the wrong bitness, where do I get the right one?
That depends on which driver you want to use.
A list of common drivers with download locations (all 32-bit and 64-bit at the same URL):
The Microsoft ODBC Driver 17 for SQL Server
The Microsoft Access database driver, which is part of the Microsoft Access Database Engine. Note that simultaneous installations of 32-bit and 64-bit Access ODBC drivers are not supported.
The MySQL ODBC connector by Oracle
The open-source SQLite ODBC driver by Christian Werner (non-official)
psqlODBC, the official PostgreSQL driver
If the driver you want to use isn't listed, the location is usually easily found using Google.
In design mode, a value has been set to the property of
TFDConnection.ConnectionDefName must be empty.

How to register ODBC driver?

I have created a inventory system for my school project and I use SqlLite as standalone DB. I am able to run it as long as I install the SqlLite ODBC connection (separate installer).
But what I want is to create an installer and install the SqlLite ODBC Drivers along with my porject in one installer instead of of running two separate installer (my application and sqlLite ODBC driver installer).
Any idea how to do it? Or do you have any recommendation?
What I have done so far. I copy the SQLLite ODBC dll into my application folder and run it but an error shows telling that no ODBC driver installed. I failed to register the SqlLite odbc dll on both 32 and 64 bit windows OS.
You can use the odbcconf command to register the driver dll directly. Note there're both 32 bit and 64 bit ODBC drivers, so you will need to use the respective odbcconf command.
For example to install 64 bit ODBC driver on 64 bit machine:
odbcconf /A {INSTALLDRIVER "My Driver Name|driver=Path to my driver dll"}
To install the 32 bit driver on 64 bit machine:
%systemroot%/systemwow64/odbcconf /A {INSTALLDRIVER "My Driver Name|driver=Path to my driver dll"}
You can find more about the odbcconf command at Microsoft Docs
It was difficult to find, so i'm going to add it as an answer here on Stackoverflow. I knew the answer from spelunking the registry, but i wanted the supported method.
From Registry Entries for ODBC Components archive, we learn ODBC drivers are registered in the registry.
HKEY_LOCAL_MACHINE
SOFTWARE
ODBC
Odbcinst.ini
ODBC Drivers
will contain a value for each driver equal to "Installed":
So you would need to create something like:
HKLM\SOFTWARE\ODBC\Odbcinst.ini\ODBC Drivers
"SqlLite": REG_SZ = "Installed"
For each driver, there will then exist an
HKEY_LOCAL_MACHINE
SOFTWARE
ODBC
Odbcinst.ini
[Driver name]
In this folder is a series of Driver specifications:
Microsoft documents these items quite nicely in the Driver Specification Subkeys archive page on MSDN.
In the case of an SqlLite ODBC driver that would mean there is a key called:
HKLM\SOFTWARE\ODBC\Odbcinst.ini\SqlLite
and you would have to be sure to create all the values for the SqlLite ODBC driver.
But don't do that
Another item in the driver details is a reference count (called UsageCount). This Usage Count is not meant to be fiddled with by people; but instead is updated when you call the functions:
SQLInstallDriverEx archive
SQLRemoveDriver archive
So while you can push stuff into the registry yourself, you should be calling the documented API SQLInstallDriver.
And while it's probably safe to read the registry to see what drivers are installed, the documented say to get the list of drivers is:
SQLGetInstalledDrivers archive
What I would recommend for you is to create a bootstrapper installation package. You didn't mention the platform you are delivering for, but since you are writing about installers I will assume that the platform is Windows.
There are multiple installer frameworks you can use to create installers for your software on Windows, but the one I recently used and would recommend is WixToolset. They have some documentation on how to build bootstrapper bundles here
In great simplicity my wix bootstrapper came down to installing one exe installer and one msi installer and the configuration looked something like this (in great simplicity - the link I provided has full documentation on how to configure all the features)
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:bal="http://schemas.microsoft.com/wix/BalExtension" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<Bundle Version="..." Name="...">
<Chain>
<ExePackage Id = "x86redist" SourceFile="..." ... />
<MsiPackage Id = "myApp" SourceFile ="..." ... />
</Chain>
</Bundle>
</Wix>
in the end after building, my bootstrapper bundle looked like this
and made sure both my software and the redistributable package were installed on the machine when it was finished.
You could use exactly the same approach - the bundle could install the odbc driver using its original installer, and then install your software.

FreeTDS unixODBC concurrent connections

I'm using Golang with FreeTDS using the ODBC driver from brainman (http://code.google.com/p/odbc)
Everything works great, until I stress test the box.
Then I get the following error:
{01000} [unixODBC][FreeTDS][SQL Server]Unable to open socket
SQLDriverConnect: {08001} [unixODBC][FreeTDS][SQL Server]Unable to
connect to data source
It seems that when I try to launch multiple concurrent requests against the FreeTDS / unixODBC drivers, it fails. Is this something that is workable, or is unixODBC and FreeTDS not useable in production environments?
This sounds similar to an issue that I ran into. FreeTDS/ODBC on CentOS7 connecting to an SQLServer2005 database. I ended up creating 6 separate FreeTDS/ODBC DNS entries to have 6 discreet database connections available to use in order to resolve this issue (they were all just numbered duplicates of each other--$db, $db2, $db3, etc). It's not a great solution, but it does work (I was migrating a really old system, so my options were limited). I'd be very interested if there is a better solution than mine.

Qt ODBC - Unable to error

I'm trying to open MS Access db file with QT in Linux.
So, I have installed odbc plugin for qt:
sudo apt-get install libqt4-sql-odbc
Now there are 2 files qt4/plugins/sqldrivers directory: libqodbc.so & libqsqlite.so
So, I try to use ODBC plugin in my project. There is connection function:
bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DSN='';DBQ=/home/user/personal_base.mdb");
if (!db.open()) {
QMessageBox::warning(0, QObject::tr("Database Error"), db.lastError().text());
return false;
}
return true;
}
But application dislpays error:
[unixODBC][Driver Manager]Data source name not found, and no default driver specified QODBC3: Unale to connect
How should I fix it?
The call to setDatabaseName ends up in the ODBC function SQLDriverConnect. SQLDriverConnect defines a number of attributes you can set to declare which ODBC driver you are using and how to use it e.g., DRIVER. You told the unixODBC driver manager to load the driver "Microsoft Access Driver (*.mdb, *.accdb)" and it could not find that driver.
In unixODBC, drivers are usually defined in the odbcinst.ini file which you can usually find with the command "odbcinst -j". You'll find this article useful.
It is highly unlikely you have a Microsoft Access driver named as you've shown as this is usually the name of the MS Access driver which is only available on Windows.
To my knowledge there are only 2 ways to access MS Access DB directly from Linux using ODBC 1) mdbtools (which is old and incomplete but free) 2) Easysoft MS Access ODBC Driver which is a complete ODBC Driver but not free.
I had The same Problem with my project except that I'm using Windows. I think that this will help you:
Just change Your Driver into this Code(taken from QT Website):
db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=myaccessfile.mdb");

Datadirect Drivers for Paradox

I need to access my data stored in the Paradox database.
I have installed Datadirect drivers for accessing the paradox database and have configured the User DSN and System DSN data source connections as mentioned in all the manuals.
I still am not able to connect to my Paradox database and get :
Network Initialization error, Cannot connect to file.
I currently have :
> Control Panel>Administrative Tools> ODBC Datasource> Drivers> Datadirect Paradox 6.0
Is there anyway I can test whether my Datadirect drivers have been installed correctly? I could not find anywhere how to do the same.
Any help or advise on how I can test the the drivers would be very helpful.
Thank you.
If you find the driver name under ODBC Datasource> Drivers, the driver has been installed successfully, the error you got leads to a problem reaching database over the network.
Check your connection string and if the file you pointing is really reachable ...

Resources