Execute ms sql server queries from linux terminal - freetds

I need to query a MS SQL Server database from a linux terminal. Searching the web and this site I found freetds and then sqsh. I have installed them and seems to connect to the server but I can't get it to execute a query, I'm definitely doing something wrong.
I have configure freetds as:
[MSSql]
host = 192.168.1.4
port = 1433
tds version = 7.0
The databse server is a Sql Server 2008 r2.
When connecting I use the following command:
sqsh -S MSSql -U sa -P sa -D databasename
Which gives me a prompt like:
sqsh-2.1.7 Copyright (C) 1995-2001 Scott C. Gray
Portions Copyright (C) 2004-2010 Michael Peppler
This is free software with ABSOLUTELY NO WARRANTY
For more information type '\warranty'
1>
Then I try to enter a query like:
1> select * from C_PROPS;
But nothing happens. What am I doing wrong?, just need simple selects and updates.

I think that the semicolon_hack variable is not set.
You need to write your command like this
select * from C_PROPS
go
or, at the beginning of a sqsh session
\set semicolon_hack=on
go
now you can do
select * from C_PROPS;
or, alternatively, create a .sqshrc in your home directory and insert this snippet
#
# $semicolon_hack : This turns on the ability to use a semicolon as
# a sort of in-line go. It is kind of hacky but seems
# to work pretty well.
#
\set semicolon_hack=on

Related

How to fix the [unixODBC][Driver Manager]Data source name not found, and no default driver specified (ODBC::Error)

/local/rvm/gems/ruby-1.9.2-p320/gems/activerecord-sqlserver-adapter-3.2.12/lib/active_record/connection_adapters/sqlserver_adapter.rb:455:in `initialize': IM002 (0) [unixODBC][Driver Manager]Data source name not found, and no default driver specified (ODBC::Error)
I have working copy of my app but suddenly overnight I left my system like that and this error started surfacing. Can anyone tell how to fix this one please?
There is no definitive answer to your question since you gave us nothing to work on.
However, the possible reasons for this are:
the DSN you specified could not be found in your user or system odbc.ini files
Run odbcinst -j to find where those files are
Has someone changed/removed them?
You set ODBCINI env var or ODBCSYSINI env var to point unixODBC at the location of your odbc.ini and odbcinst.ini files and now they are not set (or changed).
Someone has removed or moved your ODBC driver
You normally run your code as user A and now you are running it as user B and you are using user datasources or set ODBCINI env var.
... probably others but if you'd given us better information we wouldn't have to guess.
You should start by setting up and configuring FreeTDS. Here is a sample configurations from my files, but I'm sure other variants will work also. One difference is that I'm using Django, but the result below still worked eventually, but it works much better with SQL authentication than with Windows Authentication.
From /etc/freetds/freetds.conf (use the IP of the server if DNS is not active for the server name).
# A typical Microsoft server
[MyServer]
host = 10.0.0.10\path
port = 1433
tds version = 7.0
From /etc/odbcinst.ini
[FreeTDS]
Description = FreeTDS
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
From /etc/odbc.ini
[ServerDSN]
Description = "Some Description"
Driver = FreeTDS
ServerName = MyServer
Server = ip_address
Port = 1433
Database = DBNAME
Then this command connects me to the database.
tsql -S MyServer -U username#servername -P password
Please verify the following:
The driver configuration file is named odbcinst.ini and is provided in the same path / directory / folder as odbc.ini
The ODBC Initialization Path is a path / directory and not an actual path to the file (i.e. /root/odbc.ini). Please provide a directory path to where both odbcinst.ini and odbc.ini files exist.
The Driver name defined in odbcinst.ini is the same as the Driver attribute defined in the datasource of odbc.ini.
Note: If odbcinst.ini has the driver defined as “[ODBC Driver 13 for SQL Server]” then verify the odbc.ini references “Driver=ODBC Driver 13 for SQL Server”
This solved my problem.
Source: https://support.microfocus.com/kb/doc.php?id=7017884
just a tip, in my case was not possible with Driver = FreeTDS and both variables "servername" and "server" in odbc.ini. I let only "server = ip" and
"Driver = /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so", worked fine.

neo4j script file format - is there any?

I would like to predefine some graph data for neo4j and be able to load it, maybe via a console tool. I'd like it to be precisely the same as MySQL CLI and .sql files. Does anyone know if there exists a file format like .neo or .neo4j? I couldn't find such thing in the docs...
We usually do .cql or .cypher for script files. You can pipe it to the shell to run it, like so:
./neo4j-shell -c < MY_FILE.cypher
Michael Hunger was doing some great work on this feature, also, just recently. He got performance up and noise down from the console. I hope it gets into 1.9 release.
From https://groups.google.com/forum/#!topic/opencypher/PO5EnspBLs0
1:
"Sorry for the late reply, but we just wanted to inform you that the official recommendation is to use .cypher.
We'll be formalising this in the style guide soon."
2:
"In training run by Neo4j, we've historically used .cyp. I believe the preference is to use .cypher, and .cyp when an extension of 3 chars is required."
3:
"Note: '.cql' is already used for Cassandra - https://cassandra.apache.org/doc/cql/CQL.html"
From the above extracts:
1st preference is .cypher
2nd preference is .cyp (1st 3 characters of cypher)
Don't use .cql
More:
If you need a color coding in notepad++, download the xml given at https://gist.github.com/nicolewhite/b0344ea475852c8c9571 , import it via menu Language > User Defined Language > Import > Restart the Notepad++, open a file with .cypher that has some cyper query language)
Sample cypher is below:
MATCH (:Person {name: "Ann"}) -[:FB_FRIENDS]-> Create (:Person {name: "Dan"})
Hope that helps someone.
Using neo4j-client as the CLI for Neo4j allows for easy evaluation of scripts. There are several ways to work with a script containing multiple cypher commands:
You can pipe the script in via standard input, e.g.:
neo4j-client -u neo4j -P localhost < my_script.cyp
You can use the command line option --source or -i, e.g.:
neo4j-client -u neo4j -P -i my_script.cyp localhost
You can start an interactive shell, and then source the script:
$ neo4j-client localhost
Username: neo4j
Password: *****
neo4j-client 1.2.1.
Enter `:help` for usage hints.
Connected to 'neo4j://neo4j#localhost:7687'
neo4j>
neo4j> :source my_script.cyp
The extension .cyp is most commonly used for scripts.

How to use -I backend with Mdb-tools 0.7~rc1-4?

I want to convert ms-access database to sql via mdbtools.
on ubuntu 11.10 32bit with mdbtools 0.5.99.0.6pre1.0.20051109-7.1 when i am using mdbtools -I backend is working fine. i.e. i got file with Insert statement.
but on ubuntu 12.04lts 64bit, mdbtools, 0.7~rc1-4 i am not able to convert mdb file into sql file.
my syntax is :
mdb-tools -I >
please let me know any correction is needed.
Thanks in advance.
mdb-tools -I access shuld work
Supported backends are: access, sybase, oracle, postgres, mysql

Programmatical register a Postgres Server with pgAdmin using Delphi

Im working on an application using Postgres 9 and Delphi 7 as the front end,
For setting up the database connection to the application we have to do the following steps
1.Register a server in postgres
(i cannot post an image because im new user)
Name:=Localhost
Host:=Localhost
Port:=5432
SSL:=
MaintenanceDB:=myDB
Username:=Admin
password:=******
.
.
Service:=Localhost
2.Create the database and the tables.
Can any one tell me if the step 1.
can be done programatically?
Like for example
"C:\Program Files\PostgreSQL\9.0\bin\psql.exe" -h localhost -p 5432 -d myDB -U Admin Service=Localhost " ?
as of now its done manually by the user.
thanks in advance:)
The registered servers in pgAdmin are stored in the Windows registry under HKEY_CURRENT_USER\Software\pgAdmin III\Servers
The number of registered servers is stored in the Count attribute.
Then each server gets its own entry according to the number. So the first one is stored in HKEY_CURRENT_USER\Software\pgAdmin III\Servers\1, the second one in HKEY_CURRENT_USER\Software\pgAdmin III\Servers\2 and so on.
Have a look into your registry and create an approriate entry from within your Delphi application.

How to dump data from mysql database to postgresql database?

I have done the depot application using mysql... Now i am in need to use postgres... So i need to dump data from mysql database "depot_development" to postgres database "depot_develop"...
Here you can find some interesting links http://wiki.postgresql.org/wiki/Converting_from_other_Databases_to_PostgreSQL#MySQL
Have you tried to copy the tables from one database to the other:
a) export the data from MySQL as a CSV file like:
$> mysql -e "SELECT * FROM table" -h HOST -u USER -p PWD -D DB > /file/path.csv'
and then,
b) import it into Postgres like:
COPY table FROM '/file/path.csv' WITH CSV;
This question is a little old but a few days ago i was dealing with this situation and found pgloader.io.
This is by far the easiest way of doing it, you need to install it, and then run a simple lisp script (script.lips) with the following 3 lines:
/* content of the script.lisp */
LOAD DATABASE
FROM mysql://dbuser#localhost/dbname
INTO postgresql://dbuser#localhost/dbname;
/*run this in the terminal*/
pgload sctipt.lisp
And after that your postgresql DB will have all of the information that you had in your MySQL SB
On a side note, make you you compile pgloader since at the time of this post, the installer has a bug. (version 3.2.0)

Resources