Accessing Microsoft SQL Server from Tcl running on GNU/Linux - sql-server

I'm looking for a source to explain how to use connection-strings, as a client from Linux. I am working with tcl in Linux environment and get a connection-string that supposed to connect me to a Microsoft SQL server.
Do you know of a good source that shoes how to connect to a server with a connection string, and how to connect from Linux?
All the sources I found online talk about creating server strings, and don't address Linux usage at all.

Your question per se has no sense: "connection strings" is the concept which is not inherent to programming languages or database servers. Connection strings pertain to database connection libraries and usually they even differ between different database drivers used by those libraries.
Now back to the point. Personally, I'm using tclodbc with the FreeTDS driver. How to build connection strings for the FreeTDS ODBC driver, is explained here.
I do not use connection strings directly; instead I use "ODBC sources" which are configured system-wide, in the /etc/odbc.ini file (managed by the unixodbc as packaged in Debian). Basically, that file contains entries like this:
[SERVER1]
Description = MS SQL Server on server1.domain.local
Driver = /usr/lib/odbc/libtdsodbc.so
Servername = SERVER1
and the /etc/freetds/freetds.conf file contains matching entries like this:
[SERVER1]
host = server1.domain.local
port = 1433
tds version = 7.0
client charset = UTF-8
Now, in my Tcl code I have something like this:
set source SERVER1
database connect dbconn $source $user $password
...

Related

Use the TDS Remoting feature of the CData ODBC Driver for mongodb to set up a linked server for MongoDB data

I installed the CData ODBC Driver for MongoDB to make the application that can access SQL Server connect to mongodb.
According to the official document,I have configured the system DSN.
Then I modified the config file 'CData.ODBC.MongoDB.Remoting.ini' config file screenshot:-
,in which the users and passwords was the same as what I typed in DSN.
I started CData.ODBC.MongoDB.Remoting.exe and the console printed
Test connection successful. CData ODBC Driver For MongoDB 2015
remoting server starts.Local port :3309.
But when I created a linked server from SQL Server Management Studio linked server info
,it showed that the user 'noobwulei' login failed.
I am searching for a long time on net. But no use. Please help or try to give some ideas how to achieve this.
Based on the console output, looks like the remoting service isn't running on the expected port:
... Local port :3309.
According to the Help documentation (http://cdn.cdata.com/help/DGB/odbc/pg_cli.htm) the executable runs the MySQL daemon by default.
In order to run the TDS daemon, you will need to run the executable from the command line and pass TDS as the protocol option (-t):
\> CData.ODBC.MongoDB.Remoting.exe -t TDS

Connect to Ms SQL with RODBC without dsn

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

Set DSN encoding for ODBC Driver 11 for SQL Server on Windows 10

TL;TR
How force this ODBC driver to encode in UTF-8?
Detailed description
I'm writing PHP 5. 5. application which connects to database Microsoft SQL Server 2014 via PDO using ODBC driver. More specifically I'm using "ODBC Driver 11 for SQL Server".
I run application in two environments (platforms):
Production - Linux/Ubuntu/Appache PHP/UnixODBC
Development - Windows 10/Wamp
To configure PDO connection, I'm using DSN sources. To connect to SQL server I use command below:
$conn = new PDO("odbc:mssql_test", $user_name, $password);
Since it's PHP application, I require data from SQL to be returned in UTF-8 encoding. Data in database have czech characters, which is tricky, when data are not encoded in UTF-8.
On production platform, everything works fine. Queries are return as expected (in UTF-8).
However, I was not able configure DSN on Windows 10 (development platform), to get data in UFT-8 (it's seem that I'm getting data encoded in win1250) which is notable when Czech characters occurs as question mark in the result of query.
To configure DSN I'm using Windows DSN management tool located at:
C:\Windows\System32\odbcad32.exe
I added DSN to tab System DSN, but there is no option to set encoding.
Is there any way or work around to get data in UTF-8 on Windows 10 (without using PHP way such as iconv, mb_convert_encoding, since its only development issue resp. DSN configuration issue).
Please note that I've tried thinks like, without success:
$conn = new PDO("odbc:mssql_test", $user_name, $password, array("charset" => "UTF-8"));
$conn->exec("set names utf8");
or (code below works, but UTF-8 is not obtained on Windows)
$dsn = "odbc:DRIVER={ODBC Driver 11 for SQL Server};SERVER=$server_address};CHARSET=UFT-8";
$conn = new PDO($dsn, $user_name, $password);
Any help would be really appreciated!
EDIT after 3 months
I end up with switching into FreeTDS and Linux for development as well as production environment. For the time being its seem to impossible to configure ODBC driver 11 to encode in UTF-8 while using PHP 5.5. on Windows 10...
When using ODBC on Windows, the database client charset is defined in the language settings for non-Unicode applications. The current ANSI code page (ACP) is used by the SQL Server client.
On Windows 10, click Start and type Region, select Region & language settings and click Administrative language settings. Click Change system locale and check Use unicode UTF-8 ...
That should do the trick.

Cross Server script execution oracle

I am having DB server on another machine and having asp.net application installed on local machine.
I want to connect remote DB and execute my scripts, since my local machine doesn't have oracle installed
I have go-ogled and tried few links it tells me editing transnames.ora file adding one new entry
But this will not work since my local machine doesnt contain sqlplus
So I would like to now what are the tools I will need to download on local application server to run my scripts.
You need to install oracle driver to communicate with remote server.
There are multiply options:
This 2 will have tnsnames.ora file that you we told about:
Full oracle client
Oracle instant client (small in size)
Tool specific:
oracle jdbc driver for java
cx_oracle for python
something else for other tool
OS specific:
on windows you can setup an ODBC driver to connect to ORACLE
Thanks abhi, filename is corrected.
After installing a client, you need to know where is your database server.
In simple situation you need host, port and sid.
entries in tnsnames.ora look like this:
connectionName =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS =
(PROTOCOL = TCP)
(HOST = yourHost)
(Port = yourPort)
)
)
(CONNECT_DATA =
(SID = yourSID)
)
)
You fill in all information and save the file.
after that you can check connection ( I don't know, if tnsping is shipped with instant client)
>tnsping connectionName
OK (description of a connection)
Useful tip: you can just go to remote server (or some other PC that have db access already configured) and tnsping some connection (you probably already have a standard name for it).
than just grap the output in brackets and put it into your tnsnames.ora.
your connection string:
username/password#connectionname
btw, instead of conenctionname you could put the whole connection descriptions (from tnsnames.ora)
username/password#(description=...)
Now you can use the Oracle Managed Driver which does not require the installation of the Oracle Client on the machine. This is extremely helpful as Oracle Client installations are painful. It requires nothing more than putting the driver in your bin directory and providing an appropriate connection string and provider name.
To install the managed driver via NuGet run...
Install-Package odp.net.managed
You may need to change the provider name (I believe it's Oracle.ManagedDataAccess off the top of my head).
Example connection string...(replace MyHost, MyPort (usually 1521), MyOracleSid, myUsername, and myPassword with appropriate info).
SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort))(CONNECT_DATA=(SERVICE_NAME=MyOracleSID)));
uid=myUsername;pwd=myPassword;

How do I access a SQL Server database from a Perl script in Linux?

I have a Perl script on a Linux (Ubuntu 8.10) machine and I need to write data to a SQL Server Database. I've been trying to use the DBD::ODBC module but I can't get it to connect. Where can I get a free/open source driver to use to use for the ODBC connection or is there another way to do this from Perl on Linux?
I connect to SQL Server 2005 with the stack of unixODBC, freeTDS (this is the driver) and DBD::ODBC.
After you install these components, edit /etc/unixODBC/odbc.ini to read like this:
[DNS]
Description = my database
Driver = /usr/lib/libtdsodbc.so #path to freeTDS driver
Server = ServerName
Database = DatabaseName
Port = 1433 #sql server default port
TDS_Version = 9.0 #9.0 is sql server 2005
try domain login = yes
try server login = yes
nt domain = DOMAIN
If all goes well, you should be able to connect with:
$dbh = DBI->connect('dbi:ODBC:DNS', "userName", "passWord");
Good luck!
Use the DBD::Sybase module, at one point Sybase and MS SQL Server shared a common codebase.
You may also want to investigate the open source FreeTDS libraries. See the FreeTDS FAQ Question "Which Perl library should I use".

Resources