How to query a remote SQLAnywhere16 db using Rails? - sql

I am trying to set up a Rails app to query a remotely hosted SQLAnywhere 16 db and to display some query information as HTML. I'm using current versions of Ruby and Rails on Mac El Capitan. The remote server is running Windows. The server is located in my building and I am on the same LAN, so if there's a simpler solution that involves accessing the box itself physically I'm open to that.
On my Windows machine I am able to connect to the server and do queries on the db using a SQL client.
I have sqlanywhere and activerecord-sqlanywhere-adapter gems installed. I also have the SQL Anywhere 16 client installed on my (Mac) machine. The remote db set up in my database.yml file as another db:
my_external_database:
adapter: sqlanywhere
encoding: utf-8
username: (username)
password: (password)
server: (name of server)
database: (db name)
host: (IP of server)
I'm calling it like so:
class MyExternalModel < ActiveRecord::Base
establish_connection(:my_external_database)
self.table_name = '<a particular table in the db>'
self.primary_key = 'primarykey'
end
When I go into the rails console and do MyExternalModel.first to test the connection, I get:
LoadError: Could not load SQLAnywhere DBCAPI library
After doing some googling, this seems to be a problem with configuring SQLAnywhere. However, I believe I configured it properly (in bash using bin64 config), like so:
. /Applications/SQLAnywhere16/samples/sample_config64.sh
Enter destination directory for copy of the samples [/Users/(user)/sa16_samples]:
Copying samples...
Done
Setting up data sources...
SQL Anywhere Data Source Utility Version 16.0.0.2041
Configuration "SQL Anywhere 16 Demo" written to file /Users/(user)/.odbc.ini
SQL Anywhere Data Source Utility Version 16.0.0.2041
Configuration "SQL Anywhere 16 CustDB" written to file /Users/(user)/.odbc.ini
Done
Setting up sample_env script...
Done
This is as far as I'm able to get. Any recommendations are greatly appreciated!

I use SQLAnywhere for a production server and it works fine using the very same gem you're using. I use a Mac for development and my database is running in Windows (or Linux).
In order to get rid of this error, try the command (on your Mac):
# adjust SQLAnywhere to your version -> 16
source /Applications/SQLAnywhere12/System/bin64/sa_config.sh
I'm using Rails 4 and SQLAnywhere 12 (but tested with 16 and it works too).
After that, try to load console (rails c) and do some tests there.

Related

VS code can't ssh to server: failed to create hard link

SETUP
I have a windows 10 PC connecting to my linux server (ubuntu 18.04.2). I run/edit code on my powerful server by remotely accessing the server through VS code's ssh ability. It is super convenient to edit my code on the server with VS code...
THE ISSUE
Visual Studio code won't connect to my Linux server. What is weird is that I am able to ssh into the server from the terminal within VScode by just literally typing ssh <username>#<server-hostname>
However, when I do the Remote-SSH option within VScode then it does not want to connect to the server...strange...
Here is how I remotely SSH into server with VScode built in functionality (marked with red rectangle). Also part of this screenshot is my config file, which I have triple checked as correct (IP address and .ssh/id_rsa_gpu_1_solarpv_ssh location)
HERE IS THE ERROR OUTPUT
MY ATTEMPTS
I have made sure that the config file is setup correctly and that the IP address is correct.
I have ensured that the server's IP address is also in the 'known_hosts' file located at /Users/.ssh/
I even generated my own private key for SSH connection as advised by the great documentation here: https://code.visualstudio.com/docs/remote/troubleshooting#_quick-start-using-ssh-keys
Still getting the error of failed to create hard link...
With all of my back-end stuff done right, I am absolutely clueless regarding why this is an issue.
After spending literally 9 hours on this issue...here is the answer:
When you launch VScode and remotely access the linux server, the linux server is instructed to download and install a vscode server so that you (on the other side) can remotely connect to the server.
If the server does not have internet just make sure the following setting is ticked
This allows the remote server (without or with internet connection) to get the vscode server running.
To eliminate the "failed to create hard link error" go to the directory mentioned by the error, which in this case on linux server is
navigate to /home/<username>/.vscode-server/bin/0ba0ca.../
then remove/delete the hardlink file and target file which also has
the same name as the directory.
Then just attempt to remotely access your server again through
vscode and all should be fine
Here is also a discussion regarding the issue...if you still have problems https://github.com/microsoft/vscode-remote-release/issues/2507
I solved this by enabling the option Lockfiles in Tmp:
i just deleted the whole library and it works, i don't see anything wrong with doing that.
rm -r /path_to_project/.vscode-server/
if i'm wrong feel free to correct me :)
Try this
Just in case others need to try the same here is the detail
ctrl-shift-p and choose:
Remote-SSH: kill VS Code Server on Host...
Chose the host name
Selected the platform type (linux)
https://github.com/microsoft/vscode-remote-release/issues/4307#issuecomment-762882247
worked for me.

Cannot Create Default Instance in SSMS 2016

I am trying to create a default instance of SSMS to run through a few quick tutorials on my local machine. However, everything I am reading is telling me that this default instance should have been created during the wizard. Welp, I have now installed and uninstalled SSMS 2016 three times and am yet to be prompted by anything other than a simple request to install and a notification that the request is complete.
I have read online that I should use the SQL Server Management 2016 Application to create this instance, but every time I try to open that application I get this wonderful error "Cannot connect to WMI provider. You do not have permission or the server is unreachable".
I have tried running the command referenced in this article to fix the error:
https://support.microsoft.com/en-us/kb/956013
But had no luck.
I've also tried to attempt to connect to what might be the default value for the instance:
-localhost
-myip
-(local)
etc..
But when I ran osql -L earlier, it showed no SQL databases on my machine and since my most recent install this command isn't even working.
You dont create instances with SSMS. SQL Server Management Studio is to query and manage existing instances.
You use the Installation media to create an instance.
Look for the Configuration manager to see what instances you have installed.
The default instance is always called MSSQLSERVER.
According to the article you linked to, you probably jacked the installation between the 32 and 64 bit versions of SQL Server.
I suggest to use the setup program and reinstall it.

Connection to an instance-specific SQL Server DB from a Rails Application

We are connecting to a SQL Server application from a Rails 4 application running on Heroku. Everything used to work fine. We used Proximo to give us a static IP address we could then allow through our Firewall. A simple ENV variable was used on heroku to store the SQL Server request URI like so:
# Gemfile
gem 'activerecord-sqlserver-adapter'
gem 'tiny_tds'
# customer.rb
class Customer < ActiveRecord::Base
establish_connection(ENV["MS_SQL_DATABASE_URL"])
..
end
MS_SQL_DATABASE: sqlserver://username:password#176.32.98.166/DATABASE1?autocommit=true&timeout=5000
Now this all works fine, until the database was updated to a newer version and Database1 now moved to a new instance called Instance1. So in order to connect to the upgraded database we need to specify an instance name as part of our connection uri.
Specifying the instance name works locally when we VPN into the network and use the following connection URL
MS_SQL_DATABASE: sqlserver://username:password#192.168.168.1/DATABASE1?autocommit=true&timeout=5000&dataserver=192.168.168.1%5CINSTANCE1
Note we are using the dataserver property and specifying the full path to the server. The server name inside the network is known as 192.168.168.1 and also as server1. But from outside the network (on Heroku) we cannot address it like that.
What will be the proper way to address the server name to specify the instance name to allow a connection from heroku?
Is it even possible to do this? If not, what are some alternatives?

Migrate mysql users to another server

I have created a mysqldump --all-databases and transferred all my databases to the new server. It didn't work as debian-sys-maintusers password didn't match. So I change the password of this user. After that I restart my server and got this error.
ERROR 1577 (HY000) at line 1: Cannot proceed because system tables
used by Event Scheduler were found damaged at server start ERROR 1547
(HY000) at line 1: Column count of mysql.proc is wrong. Expected 20,
found 16. The table is probably corrupted
I dont know how many more errors will come after this. So I thought create dump with only databases which are associated with my applications (mysqldump --databases).
Now how do migrate the users? Is there any standard way?
More Information:
New Server version: 5.1.63-0+squeeze1 (Debian)
Old Server version: 5.0.51a-24+lenny5 (Debian)
You probably need to run mysql_upgrade, since your MySql versions are different.
As a general rule, however, do not copy the mysql system schema from one server to another. As a consequence, and as far as I know, there is no "standard" way of copying users and user privileges from one server to another.
If you really want/need to do it, try the following:
$> mysql --silent --skip-column-names -e"show grants for user#host"
The above outputs GRANT statements that you can feed straight away into your target server to create the user and give the same authorisations.
However, if your target server is empty, you could just move the whole data folder from your old server to the new server, and then run the standard upgrade procedure from 5.0 to 5.1 on the new server.

how to connect to a file based HSQLDB database with sqltool?

I have tried to follow the instructions in chapter 1 of the HSQLDB doc and started my server like:
java -cp hsqldb-2.2.5/hsqldb/lib/hsqldb.jar org.hsqldb.Server -database.0 file:#pathtodb# -dbname.0 xdb
and I have reason to believe that worked cause it said (among other things):
Database [index=0, id=0, db=file:#pathtodb#, alias=xdb] opened sucessfully in 2463 ms.
However at the next step I try to connect using SqlTool and based on chapter 8 of the documentation I came up with this command to connect:
java -jar hsqldb-2.2.5/hsqldb/lib/sqltool.jar localhost-sa
Which gives the following error:
Failed to get a connection to 'jdbc:hsqldb:hsql://localhost' as user "SA".
Cause: General error: database alias does not exist
while the server says:
[Server#60072ffb]: [Thread[HSQLDB Connection #4ceafb71,5,HSQLDB Connections #60072ffb]]: database alias= does not exist
I am at a loss. Should I specify alias when connecting somehow? What alias would my database have then? The server did not say anything about that...
(also, yes I have copied the sqltool.rc file to my home folder.
Your server has -dbname.0 xdb as the database alias. Therefore the connection URL should include xdb. For example jdbc:hsqldb:hsql://localhost/xdb
The server can serve several databases with different aliases. The URL without alias corresponds to a server command line that does not include the alias setting.
java -jar /hsqldb-2.3.2/hsqldb/lib/sqltool.jar --inlineRc=url=jdbc:hsqldb:localhost:3333/runtime,user=sa
Enter password for sa: as2dbadmin
SqlTool v. 5337.
JDBC Connection established to a HSQL Database Engine v. 2.3.2 database
This error has been hunting me for the last 5 hours.
Together with this stupid error: HSQL Driver not working?
If you want to run your hsqldb on your servlet with Apache Tomcat it is necessary that you CLOSE the runManagerSwing.bat. I know it sounds trivial but even if you create the desired database and you run Eclipse J22 Servlet with Tomcat afterwards, you will get a bunch of errors. So runManagerSwing.bat must be closed.
See my sqltool answer over on the question "How to see all the tables in an HSQLDB database". The critical piece is setting up your sqltool.rc correctly and putting it in the right location.
You can also use the following statement for getting a connection from a files based store. this can be used if you are running the application from Windows.
connection = DriverManager.getConnection("jdbc:hsqldb:file:///c:/hsqldb/mydb", "SA", "");