Cakephp2 on linux does not work with Sql Server (mssql) - sql-server

I am having a hard time installing drivers for ODB Mssql. I need it to let my php communicate with an Sql server (2005).
The driver:
http://www.microsoft.com/en-us/download/details.aspx?id=28160
Does someone know a alternative solution? Or an working example?
Please notice I am using cakePhp version 2+. Not 1.3.. Lots of documentation about this problem has been written for 1.3.
The driver for Mssql from MS is buggy. It needs a lot of libraries and still doesnt survive it's own installer..
My configuration is Ubuntu 12+ (with gui), Lampp (xampp for linux).

Besides that you have issues installing the driver, CakePHP2 has no datasource for PDO and ODBC.
You can use this datasource to connect to SQL 2005 from CakePHP 2 without PDO and the driver.
This is a ported version of the 1.3 source: https://github.com/rchavik/datasources/tree/mssql-2.0

I am not sure, but check its useful for you:
http://www.mindfiresolutions.com/Configuring-MSSQL-Server-to-talk-to-PHP-in-Ubuntu-1810.php

Related

Can we connect to any version of oracle using cx_oracle library python?

I am trying to write a script to connect to all version's of oracle database starting from the latest to the oldest version of database.
I tried myself with cx_oracle library found like it needs a client library in the local to connect to remote database like if I download the latest version then it will work up to latest few versions not all.
Also tried with Sqlalchemy connection which is also using cx_oracle libraries.
Please do guide me if am doing anything wrong? I would also like to hear if there are any other ways to connect to the database using PYTHON
cx_Oracle 6 and higher already support connecting to any Oracle database from 9i all the way up to 18c depending on the client that you are using. cx_Oracle requires Oracle Client libraries at least at 11.2. You can see the interoperability notes here. Since anything earlier than 11.2 is no longer supported anyway, that should be adequate in almost all circumstances.
You can also use ODBC to connect to the database but that won't perform as well as cx_Oracle does.
I have an 11.2 Oracle database client on my corporate Windows 7 laptop and use cx_Oracle to connect to databases from version 9.2 to 12.2 without any difficulty.
The other way I connect to databases of all versions is to wrap Python around the Linux version of Oracle's sqlplus utility. This way I do not need to install cx_Oracle and can run with an older Oracle client and the version of Python that comes with the Linux distribution. In my case I am running on Redhat 6 which comes with Python 2.6. I connect to databases from version 8.1 to 12.2 in this way.
I have a blog post about how I run sqlplus from Python on Linux: https://www.bobbydurrettdba.com/2016/11/04/running-sqlplus-from-a-python-script/
Bobby

Linux + Django + SQLServer

I am writing a Django application which needs to intereact with a SQLServer Database. I use the Django MSSQL Backend ADO.
I am trying to use it in a Linux machine (CentOS 6.4), but for the moment I am not able to establish the connection.
Anyone has suceeded on it or knows if it is possible to connect to django-mssql from a Linux environment?
Note: I've found this question but it is quite old. I am looking for an up-to-date answer.
Edit: The error I am receiving is the following. Remark that it is a Linux machine.
django.core.exceptions.ImproperlyConfigured: 'sqlserver_ado' isn't an available database backend.
Edit 2: PyWin32 is a requirement for the django-mssql package. But is possible any workaround for Linux?
Django-MSSQL only works on Windows, hence the pywin32 dependency (Actually, anything ADO is Windows dependent since it's built on Microsoft's ActiveX).
Try Django-SQLServer. It's based on Django-MSSQL but can pass info using python-tds which is not platform specific.
I will suggest to use django-pyodbc-azure instead of Django-MSSQL
Supports Django 2.0.3
Supports Microsoft SQL Server 2008/2008R2, 2012, 2014, 2016, 2017 and Azure SQL Database
Compatible with Micosoft ODBC Driver for SQL Server, SQL Server
Native Client, and FreeTDS ODBC drivers

Mac OS X + cakephp + SqlServer

I am using Mac OS X, I am trying to connect to SqlServer from Cakephp2.0 application but it says "Cake is NOT able to connect to the database."
When I looked into the Cakephp datasource classes, In Sqlserver.php, it was checking for the the available drivers using PDO::getAvailableDrivers(), it was not returning the sqlsrv driver.
Is anyone tried connecting to Sql Server using sqlsrv (Provides access to Microsoft SQL Server database servers. developed, supported by Microsoft) using cakephp2.0 on Mac OS X.
Thanks in advance. Any help will be appreciated.
Just to clarify, Microsoft's sqlsrv Database Extension only works on Windows.
Also, the PDO_SQLSRV PDO driver that datasource uses only works on Windows:
The PDO_SQLSRV extension is only compatible with PHP running on Windows. For Linux, see ODBC and ยป Microsoft's SQL Server ODBC Driver for Linux.
There are the alternatives above, but I believe you will probably want to compile FreeTDS to get up and running (potentially following this guide):
PDO_DBLIB is a driver that implements the PHP Data Objects (PDO) interface to enable access from PHP to Microsoft SQL Server and Sybase databases through the FreeTDS libary.
Install Xcode (comes with headers and compiling tools such as gcc, make, etc.)
Install a package manager (homebrew, fink, macports)
(optional) Install UnixODBC
Install FreeTDS (configured to use your built in iODBC or UnixODBC)
Configure ODBC settings.
But first of all I would follow this ticket as it seems to offer some advice specifically about CakePHP and what datasource changes may need required.

What are some ways of accessing Microsoft SQL Server from Linux?

We have a Windows machine running SQL Server 2005, and we need to be able to run some database queries on it from a Linux box. What are some of the recommended ways of doing this? Ideally, we would want a command-line utility similar to sqlcmd on Windows.
FreeTDS + unixODBC or iODBC
Install first FreeTDS, then configure one of the two ODBC engines to use FreeTDS as its ODBC driver. Then use the commandline interface of the ODBC engine.
unixODBC has isql, iODBC has iodbctest
You can also use your favorite programming language (I've successfully used Perl, C, Python and Ruby to connect to MSSQL)
I'm personally using FreeTDS + iODBC:
$more /etc/freetds/freetds.conf
[10.0.1.251]
host = 10.0.1.251
port = 1433
tds version = 8.0
$ more /etc/odbc.ini
[ACCT]
Driver = /usr/local/freetds/lib/libtdsodbc.so
Description = ODBC to SQLServer via FreeTDS
Trace = No
Servername = 10.0.1.251
Database = accounts_ver8
sql-cli is a nodejs based cross platform command line interface for sql server. You can install it via npm https://www.npmjs.org/package/sql-cli
It can connect to both on-premise and sql azure instance.
sqsh + freetds.
sqsh was primarily an isql replacement for Sybase SQL Server (now ASE) but it works just fine for connecting to SQL Server (provided you use freetds).
To compile, simply point $SYBASE to freetds install and it should work from there. I use it on my Mac all day.
The best part of sqsh are the advanced features, such as dead simple server linking (no need to set up linked servers in SQL Server), flow control and looping (no more concatenating strings and executing dynamic SQL), and invisible bulk copy/load.
Anyone who uses any other command line tool is simply crazy! :)
pymssql is a DB-API Python module, based on FreeTDS. It worked for me. Create some helper functions, if you need, and use it from Python shell.
Mono contains an ADO.NET provider that should do this for you. I don't know if there is a command line utility for it, but you could definitely wrap up some C# to do the queries if there isn't.
Have a look at http://www.mono-project.com/TDS_Providers and http://www.mono-project.com/SQLClient
Since November 2011 Microsoft provides their own SQL Server ODBC Driver for Linux for Red Hat Enterprise Linux (RHEL) and SUSE Linux Enterprise Server (SLES).
Download Microsoft ODBC Driver 11 for SQL Server on Red Hat Linux
Download Microsoft ODBC Driver 11 for SQL Server on SUSE - CTP
ODBC Driver on Linux Documentation
It also includes sqlcmd for Linux.
If you are using Java, have a look at JDBC.
http://msdn.microsoft.com/en-us/library/ms378672(SQL.90).aspx
http://en.wikipedia.org/wiki/Jdbc
You don't say what you want to do with the resulting data, but if it's general queries for development/maintenance then I'd have thought Remote Desktop to the windows server and then using the actual SQL Server tools on their would always have been a more productive option over any hacked together solution on Linux itself.
There is an abstraction lib available for PHP. Not sure what your client's box will support but if its Linux then certainly should support building a PHP query interface with this:
http://adodb.sourceforge.net/ Hope that helps you.
I'd like to recommend Sqlectron. Besides being open source under MIT license it's multiplatform boosted by Electron. Its own definition is:
A simple and lightweight SQL client desktop with cross database and platform support
It currently supports PostgreSQL, MySQL, MS SQL Server, Cassandra and SQLite.
Surprised no one has mentioned that, contrary to what other answers seem to suggest, FreeTDS is all you need. No need for unixODBC, iODBC or anything else on top of it.
run some database queries [...] command-line utility similar to sqlcmd on Windows
tsql does this and is part of the FreeTDS package (as are freebcp and other utilities). tsql does not have fancy UI, but if you want a command-line utility that is light, functional and performant, it'll do just fine.
See e.g. How to run a SQL script in tsql
And by light, I mean under 500kb in size (maybe under 60k depending on how it's compiled) and, as far as I have seen, extremely efficient with memory and CPU.
I was not confortable with the freetds solution,
it's why i coded a class (command history, autocompletion on tables and fields, etc.)
http://www.phpclasses.org/package/8168-PHP-Use-ncurses-to-get-key-inputs-and-write-shell-text.html
valentina-db it has free version for sql server
.rpm and .deb
serial id will be sent by email after registration
https://www.valentina-db.com/en/
https://valentina-db.com/en/store/category/14-free-products
If you use eclipse you can install Data Tools Platform plugin on it and use it for every DB engines including MS SQLServer. It just needs to get JDBC driver for that DB engine.
There is a nice CLI based tool for accessing MSSQL databases now.
It's called mssql-cli and it's a bit similar to postgres' psql.
Gihub repository page
Install for example via pip (global installation, for a local one omit the sudo part):
sudo pip install mssql-cli

Using Rails 2.x with MS SQL Server 2005

Does anybody here have positive experience of working with MS SQL Server 2005 from Rails 2.x?
Our developers use Mac OS X, and our production runs on Linux. For legacy reasons we should use MS SQL Server 2005.
We're using ruby-odbc and are running into various problems, too depressing to list here. I get an impression that we're doing something wrong.
I'm talking about the no-compromise usage, that is, with migrations and all.
Thank you,
Have you considered using JRuby? Microsoft has a JDBC driver for SQL Server that can be run on UNIX variants (it's pure Java AFAIK). I was able to get the 2.0 technology preview working with JRuby and Rails 2.1 today. I haven't tried migrations yet, but so far the driver seems to be working quite well.
Here's a rough sketch of how to get it working:
Make sure Java 6 is installed
Install JRuby using the instructions on the JRuby website
Install Rails using gem (jruby -S gem install rails)
Download the UNIX package of Microsoft's SQL Server JDBC driver (Version 2.0)
Unpack Microsoft's SQL Server driver
Find sqljdbc4.jar and copy it to JRuby's lib directory
jruby -S gem install activerecord-jdbcmssql-adapter
Create a rails project (jruby -S rails hello)
Put the proper settings in database.yml (example below)
You're all set! Try running jruby script/console and creating a model.
development:
host: localhost
adapter: jdbc
username: sa
password: kitteh
driver: com.microsoft.sqlserver.jdbc.SQLServerDriver
url: jdbc:sqlserver://localhost;databaseName=mydb
timeout: 5000
Note: I'm not sure you can use Windows Authentication with the JDBC driver. You may need to use SQL Server Authentication.
Best of luck to you!
Ben
Instead of running your production server on Linux have you considered to run rails on Windows? I am currently developing an application using SQL Server and until know it seems to run fine.
These are the steps to access a SQL Server database from a Rails 2.0 application running on Windows.
The SQL Server adapter is not included by default in Rails 2. It is necessary to download and install it using the following command.
gem install activerecord-sqlserver-adapter
--source=http://gems.rubyonrails.org
Download the latest version of ruby-dbi from
http://rubyforge.org/projects/ruby-dbi/
and then extract the file from ruby-dbi\lib\dbd\ADO.rb
to C:\ruby\lib\ruby\site_ruby\1.8\DBD\ADO\ADO.rb.
Warning, the folder ADO does not exist, so you have to create it in advance.
It is not possible to preconfigure rails for SQL Server using the --database option, just create your application as usual and then modify config\database.yml in your application folder as follows:
development:
adapter: sqlserver
database: your_database_name
host: your_sqlserver_host
username: your_sqlserver_user
password: your_sqlserver_password
Run rake db:migrate to check your installation. If everything is fine you should not receive any error message.
I would strongly suggest you weigh up migrating from the legacy database. You'll probably find yourself in a world of pain pretty quickly. From experience, Rails and legacy schemas don't go too well together either.
I don't think there's a "nice solution" to this one, I'm afraid.
Our developers use Mac OS X, and our production runs on Linux. For legacy reasons we should use MS SQL Server 2005.
We are developing on Ubuntu 8.04, but our production servers are running Linux (Centos) and we are also using SqlServer 2005.
From our experiences the initial setup and config was quite painful - it took a couple of weeks to get everything to play nicely together. However, it's all seemless now, and I find SqlServer works perfectly well.
We use the FreeTDS ODBC drivers which once configured are fine.
DO NOT run productions Rails apps on Windows - you're asking for trouble. It's fine for development but nothing more. Rails doesn't scale well on Windows platforms.
Hope that helps.

Resources