How sql source (RODBC) connects with Shiny? - sql-server

My question is when or in what instances gets the shiny app refreshed once a SQL RODBC connection is established (or alternatively also other types of connection like RJDBC etc.)?
I connected shiny app to a database using RODBC package:
library(RODBC)
connection <- odbcConnect(dsn, uid = "", pwd = "")
Subsequently I create an object inside R to manipulate further the data:
object<-sqlQuery(connection, "SELECT ALL * FROM <the table>;")
I keep the app running online so others can see the data visualisation. Is the shiny app refreshed from the SQL source every time someone opens the app in the browser or refreshes the browser page?
Or is it a bit more complex and I need to build in an observer in the data input pathway when reading data in from SQL server?
(Note: the SQL source is updated weekly, therefore, I cannot test this at the moment.)

I can only guess based on the code extract, but as I see it your code will never update based on reactivity. I don't see any reactivity in your code, which will automatically update the contents of object. However, it depends where your code is. If your code is inside the server object it should refresh for each session (this is user/refresh/...). However, if something reactive changes like a pressed button it will not update automatically
However you should be able to try it easily
object<-{cat("test");sqlQuery(connection, "SELECT ALL * FROM <the table>;")}

Related

Sequelize returning old data from SQL Server

Problem: what I'm sometimes seeing is that very old data is being returned from my various databases when I do SELECT operations (findAll).
I have a VueJS app in which I'm using AxiosJS to call my backend ExpressJS app which uses Sequelize to connect to several (4) SQL Server databases. I'm also using the VueJS Developer Tools so I can see the variables and Vuex store change in real time on the frontend. I'm also using console.log on the backend so I can see some things there too.
In searching for solutions, I have found that:
I'm not using transactions; all of my queries are single queries that return results to the application, so I don't (shouldn't) have issues with commit timing; i.e. I UPDATE or ADD a row and only after it returns a result do I then make a SELECT
Sequelize keeps connections open, and so old connections show as "Sleeping" in the DB; I see these do get reused over time
I'm using the default isolation level in SQL Server which is READ COMMITTED and which should return committed data; since I'm waiting for the first query to return a result before launching the second query, shouldn't it be committed and ready to get me the latest values?
I see that SQL Server CAN store old copies of rows, sometimes making SNAPSHOTS, but I think they require higher isolation levels - but I'm not sure about that; maybe it IS keeping old versions?
I've been unsuccessful in figuring out how to close and reopen Sequelize connections. I'd like to close things at logout and reconnect there too since the app is still running in the tab (if this will solve my old data problem), thereby allowing someone to relogin and open all of the DB connections to be available again. I can't figure it out based on the available docs.
I think Sequelize is using old connections and somehow it is that which is causing SELECT results to be stale - this is even more likely if SQL Server is keeping old versions of rows
For some reason, if I logout and do a hard refresh of my app (CTRL+F5), all data is fresh; I don't understand why this would be at all. What could the browser be holding on to? Note that the console logs on the server app are always consistent with whatever the frontend shows. In other words, if the backend console log is stale, the frontend is stale; if backend is fresh, frontend is too.
I am unable to duplicate the getting of stale data using SSMS or Postman
Question: So what are the possible ways I can be getting stale data when I'm using Axios on the frontend and Sequelize on the backend?

Mirth- Database writer error

I am trying to create a channel to write to a database from HTTP source.
I have made two destinations both to same database. One destination writes via JavaScript and the other with SQL.
The data gets written to database in the first destination(the JavaScript one) but not through the second(SQL). I am not able to get the tables through "Insert" button also. It gives the following error:
Someone please give me the solution to set up database connection without any flaw. Please note that the database is secured one in AWS instance.
To connect to database via javascript, you will need to select "Yes" under the option to use javascript. Then your connector will look something like this:
var dbConn;
try {
dbConn = DatabaseConnectionFactory.createDatabaseConnection('net.sourceforge.jtds.jdbc.Driver','ServerURL','Username','Password');
// You may access this result below with $('column_name')
return result;
} finally {
if (dbConn) {
dbConn.close();
}
}
Note that you can click on the "generate" button and this template will be created for you in the javascript window.
Based on the information you have given, I am not sure that your method/syntax is the cause to your error. Can you verify that your database driver jar file is located in your installation? (Mine is located at "...\Mirth Connect\server-lib\database"

Hyperledger Fabric Rocksdb Database, Retrieve and Modification

I am working around to figure out that Fabric v0.6 is really not allowed data modification illegally. Beside I want to modify data in "sst" format directly. I want to use some other such as create instance of database then retrieve all data -> Modified them -> put them back and star the peer normally. but when I try to create instance of Rocksdb, I got this error
Rocksdb Error Column Family Not opened...
Based on this tutorial: http://pyrocksdb.readthedocs.io/en/v0.4/tutorial/index.html
If it's a new database then it's fine. while it come to database of blockchain, I got this few error.

How to confirm test-data from selenium webdriver is stored in the database?

Interview questions:
Suppose you fill-up the fields (eg username , password etc) from Test data Excel sheet using Apache POI. After clicking on Submit button, what happens?
How do you confirm that test data from excel sheet in stored into DB?
What is interface between Selenium WD and the Database?
As far as Selenium is concerned, there is no direct facility given by Selenium to connect with any database to check any stored value.
To check the saved value you have to connect to databases depending on used db like mysql, oracle etc... you have to use supported api to make connection to database first then execute query. An example to execute query on mysql db using java with mysql-connector-java-5.0.8-bin.jar, below code will return a record set which you can use like any other 2 D Array:
String dbClass = "com.mysql.jdbc.Driver";
Class.forName(dbClass);
// Getting Values for dburl,dbUsername and dbPassword from configuration file
String dburl = propertyConfigFile.getProperty("dbURL").toString();
String dbuserName = propertyConfigFile.getProperty("dbUserName").toString();
String dbpassword = propertyConfigFile.getProperty("dbPassword").toString();
qaConnection = (Connection) DriverManager.getConnection (dburl,dbuserName,dbpassword);
Statement stmt = (Statement) con.createStatement();
ResultSet rs = (ResultSet) stmt.executeQuery(sqlQuery);
I would do this much like a user/manual tester would. Refresh the page, clear browser storage/cookies if you feel you should (perhaps by running some extra Javascript in the page), and go to a page where you can verify that the data was entered successfully.
Your example of username/password should be especially easy to test: they should be able to be verified by logging in with those credentials. Of course there could be a scenario where you don't let the user see or verify what they have previously done: but I suspect these are fairly rare.
I suspect also that checking exactly how the data is in the database might be beyond the usual scope of Selenium tests, and would usually be designed to pass even if you've completely re-engineered the backend. However, I see it can be argued that there is value to it being verified, especially at the initial stages of an application where the only effect of something is that something is in the database, before the UI to show it has been created. A number of databases I think offer a low-level web-ui to run queries. You could write a test that fires this up and checks that the data entered by your form is indeed in the database.

Zend prevent database connection on concrete action

Is this possible to prevent database connection while I requests concrete action in Zend Framework 2?
As Sam stated in a comment; if you do not wish to establish a connection to the database, then simply don't. If you do not have any code within your controller action that uses the database, then there won't be a database connection (provided that you are not doing funky stuff in a bootstrap method or similar).
If you are building a database connection in the standard way, then the actual connection will be lazily loaded, meaning that there won't be an actual connection before you try to use it.
In your comment you state that you believe the problem is caused by many database connections. I just want to clarify that there will only be one database connection per request (provided that you make use of the database).
If you have no code that calls a database, then your web server won't actually make a connection to your database. Either way, if you have 150+ images per page, then that would be a bigger concern and is probably the root cause for slow page loads. Perhaps consider pagination or if you do not display the pictures in their full sizes, then avoid scaling them in HTML as you would then be sending lots of unnecessary data from your web server to your visitors. You could resize the pictures in PHP when they are added, for instance. After that, you could even consider using a Content Delivery Network (CDN), but that is a different discussion...

Resources