How do you read data like tables from SQL Developer using Grails? - grails

I have fair amount of knowledge of Grails but I cannot find a way how to read data from a table from sql developers using Grails. How can I do this?

By default when you use run-app, the database is in-memory (the url is something like "jdbc:h2:mem:devDb"), so there's no way to connect to it from outside the JVM. If you change it to a "real" database you can connect to it from both Grails and another client.
To do this with H2, one option is to start a standalone server. This requires that you find the H2 jar - it will be under $HOME/.m2/repository or $HOME/.grails/ivy-cache. For example on my machine the command to start on port 9092 (the default) is
java -cp /home/burt/.m2/repository/com/h2database/h2/1.3.170/h2-1.3.170.jar org.h2.tools.Server -tcp -tcpPort 9092
Then change the url in grails-app/conf/DataSource to
url = 'jdbc:h2:tcp://localhost:9092/dbname'
where "dbname" is arbitrary - H2 supports creating multiple databases per server. You can then start Grails and it will connect to that server, and you can connect from another client too.
A simpler way to do this is to use H2's auto-server mode, e.g. with this url
url = 'jdbc:h2:./dbname;AUTO_SERVER=TRUE;AUTO_SERVER_PORT=9092'
it will start up an in-memory database but with a TCP socket on port 9092 that you can connect to externally. This avoids having to find the jar and explicitly start the database server.
See http://h2database.com/html/main.html for more configuration information.
You can also use a different server, e.g. a MySQL/PostgreSQL/Oracle/etc server.
But having said all this, there is a convenient database client already running that you can access. When you start Grails with run-app you can connect to http://localhost:8080/appname/dbconsole in a web browser and access your table information, do SQL queries, etc. This is an H2 feature, but it works with whatever database you use since it works with JDBC, so you can use it with MySQL or whatever. See http://grails.org/doc/latest/guide/conf.html#databaseConsole for more information on this.

Related

How to switch MongoDB database on the fly while using db.collection.insert()?

I have a multi-domain Rails 4 app where the request.domain of the http request determines which functionality I expose a given visitor to.
Each domain in my app should be served by its own MongoDB database. E.g. domain1.com is served by db_for_domain_1, etc.
I can read in the MongoDB docs on runtime persistence that
Mongoid.override_database("db_for_#{request.domain}")
enables me to switch database on the fly.
But how do I keep the persistence when I bypass Mongoid and use the mongo Shell method db.collection.insert()? I will still do it from within my application though.
The answer might be in the MongoDB docs on collection access, but I don't understand it. So how do I switch database before/during this operation?:
MyModel.collection.insert({field_1: "Value 1", field_2: "Value 2"})
If I understand your question correctly: you have an app that connects to different mongodbs on different servers, but want to use mongo shell to connect to the database outside of your application? If true, you would connect to the desired database through the shell with
mongo db_for_domain_1:<port>/<dbName>
and then
db.<collectionName>.insert({doc})
see mongo --help for username and password options.

SQL Server 2012 mirror in azure VM - on second failover app loses connectivity

We've got a mirrored SQL server 2012 database setup on Azure VM's - two servers plus a witness, all using client certificates, with SQL logins with the same SID set.
When testing our app from a different VM, everything works as expected when we manually failover the database, there's a one second wait and then it continues to operate quite happily.
If we then do another manual failover, ie moving the principal back to the original server, the app errors and throws a 'no such host in known' error. Recycling the app pool fixes the issue, but this clearly isn't workable in production when one of the servers is updated followed by the other at some later point (both are in an availability set).
The host not known error is somewhat baffling as it was communicating with it happily before the initial failover, and will again after the app pool recycle.
Here's the connection string as it is right now, after a lot of faffing around:
"Data Source=server1,1433;Failover Partner=server2,1433;Initial
Catalog=;MultipleActiveResultSets=True;User Id=user;
Password=password; Network=dbmssocn;Connect Timeout=60; async = true;"
providerName="System.Data.SqlClient"
The app is running on .net 4.5.2, so should be up to date with hotfixes, and we're out of ideas after much Googling with Bing.
I've just solved a problem that I had that looks very similar to your problem. I'd get the host not known error whenever the database switched from the first one listed in the web.config file to the failover one. It was fine switching from the failover to the primary.
The problem that I had was that I set up the database mirroring using server names but my web server did not know the database servers by name. Once I fixed this, I was able to get the failover working smoothly both ways.
This is what I think was happening:
I set up the mirroring using the names SQL1 and SQL2 as the principal and mirror servers
I have their ip addresses in my connection string: 10.1.1.5 and 10.1.1.6
The application tries to get to the first server 10.1.1.5 and succeeds and is then told that the mirror server is SQL2
SQL1 goes down and the database is successfully switched to the mirror server.
The web application attempts to connect, fails and determines that it should try the second server.
It tries to connect to SQL2, which it doesn't know, and fails with the message that the host is unknown.
This answer would only apply to your situation if you actually put ip addresses in your web.config and that server1,1433 and server2,1433 were actually masking place-holders for the ip addresses that you actually used.
I haven't really solved the naming issue though. I just added the two database server names to the HOSTS file which isn't an acceptable situation but does prove my theory on what my problem was.
I am researching a setup just like you have and upon reading this and the response by Steve Kaye, I'm wondering if you have SQL browser running. Take a look at this article for how SQL browser comes into play:
http://blogs.msdn.com/b/spike/archive/2010/12/15/running-a-database-mirror-setup-with-the-sqlbrowser-service-off-may-produce-unexpected-results.aspx

Lighttpd FASTCGI varying instances by path

I have a multi-tenanted application where each tenant's data is in a separate database.
I want to implement FASTCGI programs under LIGHTTPD, but I want different instances of the program for each database.
For example, I would like any connection {site}/app/c123/a/b to be routed to instances of the FASTCGI app connected to database C123, and any connection {site}/app/c578/a/b to be routed to instances connected to database C578.
For startup purposes, assume that the FASTCGI app takes a startup parameter (ie, -Dc123 or -Dc578) to select the database which it opens.
The /a/b are placeholders for elements of the path that will be passed through to any of the FASTCGI instances, regardless of the database to which it is connected. For example, {site}/app/c123/Accounts/List might return a list of accounts which are contained in the C123 database.
To support expected concurrency by tenant, I might want two instances of the app connected to database C123, eight instances of the app connected to database C578, and so on for different databases.
So, given these examples, what configuration of LIGHTTPD do I need such that 1..n instances of the FASTCGI app may be started for each database?
You can run separate backend daemons for each user
lighttpd mod_fastcgi
PHP-FPM
Alternatively, you can run a single backend and have it manage connecting to different database, as appropriate.

Connect to Multiple SQL Anywhere 11 Servers With JDBC or ODBC

Here is my situation. I have an application (Mirth Connect) running on the same server as SQL Anywhere 11. There is also another server on the same network running SQL Anywhere 11. I need to connect to both of them. They are both using the same SQL Anywhere "Server Name".
I need to use a JDBC connection to connect to either of them at any given moment. I can connect to the local instance just fine.
I tried to set up an ODBC connection to the remote server. When I test the connection it says it is all good. Then when I try to run a query I notice I am connected to the local server. It must be because both SQL Anywhere servers are using the same "Server Name".
How do I force the ODBC connection to connect to the Remote server?
Thank you!
You need to specify the IP address (and port, if not using the default) in the connection string. Your connection string must contain the LINKS parameter, with (at least) the following options:
LINKS=tcpip(HOST=<remote IP address>;PORT=<remote port>;DoBroadcast=None)
If the remote server is using the default port number, 2638, you don't need to specify the port number in the connection string. DoBroadcast=None tells the client library that it should make a direct connection to that host. The default (for version 11 and older) is to broadcast on the network looking for that server name, and whichever server responds first wins. Since there is a server on the local machine, it is very likely to respond first.
For version 12 and up, you can replace the entire LINKS parameter with the new HOST parameter:
HOST=<remote IP address>:<remote port>
which will have the same behaviour as the LINKS parameter above.
P.S. It is recommended that you give each server a unique server name, thus avoiding the need to hard-code the IP address of the host. Not to mention that you must be using some trickery to fool the second server into either (a) thinking its name is unique, or (b) not checking to see if it's unique, which it does by default. If you use unique server names, you don't need this extra stuff.
Disclaimer: I work for Sybase in SQL Anywhere engineering.

Oracle error occurred, but error message could not be retrieved from Oracle

There is a delphi application in which I am trying to connect to Oracle database Using provider MSDAORA.1 but problem is coming in connecting. Oracle error message which is coming is "Oracle error occurred, but error message could not be retrieved from Oracle"
I am able to connect to database with Oracle10g client.
Connection String: Provider=MSDAORA.1;
User ID=murat;
Password = murat;
Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp) (HOST= INGPSP)(PORT=1521))(CONNECT_DATA=(SID=INGPSP)));
Persist Security Info=False;
Please provide your expert opinion what can be the reason of this?
The service name seems to be lacking in your address.
Set a tnsnames.ora file, and use the entry as data source instead of the data_source parameter you set. Follow the steps available on the faq.
Or use use connection strings like '//host[:port]/[service_name]' for your data source: //INGPSP:1521/ServiceName
For Oracle, both Microsoft and Oracle OleDB providers are known to have issue with BLOBs. If you can, use another mean of connection.
What I see that is strange is that your HOST and SID are the same. The HOST is the name of the machine on your network and the SID is the database instance on that machine. I created the following ConnectionString for the PRD3 database on machine DB19 (there are multiple databases on DB19) on our network. I was able to connect to the database successfully with real User ID and Password.
Provider=MSDAORA.1;
Password=123456;
User ID=abc;
Data Source="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=db19)(PORT=1521))(CONNECT_DATA=(SID=prd3)))";
Persist Security Info=True
Normally the Data Source I use is the database name as defined in TNSNAMES.ORA. It is a lot less to type (fewer potential errors) and can be changed to another database without recompiling the program (such as switching between a development database and production database).

Resources