Error connecting a MongoDB database to MATLAB (Unable to load a message catalog 'mongodb:mongodb') - database

I have a MongoDB database I have storing a large dataset. I am trying to import my database into MATLAB to perform data visualization, but am getting strange errors that I have not been able to debug in doing so. I have my database running using mongod on localhost on port 27017.
I do have the Database Toolbox add on for MATLAB, and the MongoDB specific one as well.
Following the example of the MATLAB documentation, I created variables:
server = "0.0.0.0" (I have also tried putting localhost here)
port = 27017
dbname = "NYPDData"
conn = mongo(server, port, dbname)
When I do so, I recieve the error that:
Error using error
Unable to load a message catalog 'mongodb:mongodb'. Please check
the file location and format.
Error in mongo (line 389)
error(message('mongodb:mongodb:DriverError',mongo.extractExceptionMessage(e)));
When I try simple running conn = mongo() with any parameters however, it seems to work, and returns:
conn =
mongo with properties:
Database: ''
UserName: ''
Server: {}
Port:
CollectionNames: {}
TotalDocuments:
If you have any insight on how to solve this error, please let me know. Thank you!

Type this before calling the mongo function : registerrealtimecataloglocation('c:\ProgramData\MATLAB\SupportPackages\R2017b')
It should return 1 if everything goes well. Don't forget to change the previous line by your number of version (R2017b here) with yours.
And then it should find the message in the catalog.

Related

pyodbc - using try: except to detect if connection not made

I'm new at pyodbc and I'm using the following code to connect my database:
(IDE is VS Code) I'm testing the connection to ensure that an error message is displayed if I fail to connect to the server:
All is fine if the server name is correct, but if I deliberately misspell the server name in order to prove that the connection is not successful, then the code appears to hang. (VSC shows code still running and I need to manually click on Stop), so then I don't appear to reach the try/except statement.
import pyodbc
try:
conn = pyodbc.connect(Trusted_Connection='yes', driver = '{SQL Server}',server = 'xxx-xxxx\SQLEXPRESS' , database = 'master')
except pyodbc.Error as ex:
print(ex)
else:
print('Connected')
print('Done')
Thanks all
Russ

Debezium SQL Server Connector - "Couldn't obtain database name"

I'm trying to set up a Debezium SQL Server Connector against a SQL Server instance that is controlled by DBAs at my workplace. I've been able to start up Zookeeper and Kafka Server without issue, and Kafka Connect itself works with sample Connectors, but when attempting to start a Debezium SQL Server Connector instance I've been getting the error "Couldn't obtain database name".
[2022-07-12 16:36:04,269] ERROR Stopping after connector error (org.apache.kafka.connect.cli.ConnectStandalone:117)
java.util.concurrent.ExecutionException: org.apache.kafka.connect.runtime.rest.errors.BadRequestException: Connector configuration is invalid and contains the following 1 error(s):
Unable to connect. Check this and other connection properties. Error: Couldn't obtain database name
Here is my debezium config:
name=Dbz-SqlServer-connector
connector.class=io.debezium.connector.sqlserver.SqlServerConnector
database.hostname=MyDbHost
database.port=1433
database.user=MyUsername
database.password=MyPassword
database.dbname=MyDatabase
database.server.name=MyDbHost
table.include.list=dbo.CdcTest
database.history.kafka.bootstrap.servers=localhost:9092
database.history.kafka.topic=dbhistory.CdcTest
I've tried this in a .properties file passed to a standalone Connect instance, and as a JSON POST to a distributed Connect instance. I have tried all of the same steps on both my local Windows machine as well as on a linux VM, with the same results.
Confluent and Docker are not options for me in this situation.
for SQL Server login credentials, I am using a local account on the SQL Server instance that does have access to the database in question. I found the source code for debezium's connectors on their github and was able to find that specific error message within the code:
private static final String GET_DATABASE_NAME = "SELECT name FROM sys.databases WHERE name = ?";
...
public String retrieveRealDatabaseName(String databaseName) {
try {
return prepareQueryAndMap(GET_DATABASE_NAME,
ps -> ps.setString(1, databaseName),
singleResultMapper(rs -> rs.getString(1), "Could not retrieve exactly one database name"));
}
catch (SQLException e) {
throw new RuntimeException("Couldn't obtain database name", e);
}
}
I'm not completely familiar with Java but it appears that basically something is going wrong when the connector is trying to run "SELECT name FROM sys.databases WHERE name = 'MyDatabase'". When I run this against the database myself, logged in with the same account I'm using, it seems to work just fine, so I'm really not sure where to go from here. It is fair to say that since I'm not in full control of the SQL Server environment that I'm using, there may be some permissions issues that I'm not aware of, but from what I'm able to test it seems like it should be working.
I would greatly appreciate any help at all, whether just suggestions on settings/configs to check or a full-blown solution.
Thank you!
Update: I've built a simple console app to run that sys.databases query against MyDbHost, master database, as the relevant account, and it's working just fine so I feel like that confirms that my connection info is correct and account permissions are also correct. Seems like this is an issue within the Debezium connector.
It turned out that my problem was a mistake in the connector's config setting. I misunderstood which specific pieces of data to put into database.hostname and database.server.name, and one I corrected those fields the connector works.

Connecting Jmeter to an Oracle database with two hosts and service name

I am trying to connect Jmeter to a geo redundant database with two hosts and I am struggling with finding the right Database Url format.
This is how my connection string looks like:
jdbc:oracle:thin:#(DESCRIPTION=(ENABLE=BROKEN)(FAILOVER=on)(CONNECT_TIMEOUT=5sec)(TRANSPORT_CONNECT_TIMEOUT=3sec)(RETRY_COUNT=3)(LOAD_BALANCE=on)(ADDRESS_LIST=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=HostName)(PORT=port)))(ADDRESS_LIST=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=HostName2)(PORT=port)))(CONNECT_DATA=(SERVICE_NAME=ServiceName)))
Database Connection Configuration is as following:
JDBC Driver Class: oracle.jdbc.OracleDriver Username: username
Password: password
For the Database URL I tried different formats and I keep getting the error:
Cannot load JDBC driver class 'oracle.jdbc.OracleDriver'
Note that the ojdbc.jar file is in the /lib folder as per the Jmeter documentation. Also, the ports are the same for both hosts.
Any suggestion is welcome. :)
I don't think you will be able to establish the connection to Oracle RAC using JMeter's JDBC Connection Configuration as it doesn't allow full flexibility therefore you will not be able to properly instantiate the PoolDataSourceFactory
So I would recommend switching to JSR223 Test Elements and Groovy language where you will have the full freedom when it comes to setting up the connection, executing queries, accessing results, etc. The relevant code would be something like:
def prop = new Properties()
prop.put('oracle.jdbc.thinForceDNSLoadBalancing','true')
PoolDataSource pds = PoolDataSourceFactory.getPoolDataSource()
pds.setConnectionProperties(prop)
pds.setConnectionFactoryClassName('oracle.jdbc.pool.OracleDataSource'); pds.setUser('johndoe')
pds.setPassword('secret')
String dbURL =
'jdbc:oracle:thin:#(DESCRIPTION=(ENABLE=BROKEN)(FAILOVER=on)(CONNECT_TIMEOUT=5sec)' +
'(TRANSPORT_CONNECT_TIMEOUT=3sec)(RETRY_COUNT=3)(LOAD_BALANCE=on)(ADDRESS_LIST=(LOAD_BALANCE=on)' +
'(ADDRESS=(PROTOCOL=TCP)(HOST=HostName)(PORT=port)))(ADDRESS_LIST=(LOAD_BALANCE=on)' +
'(ADDRESS=(PROTOCOL=TCP)(HOST=HostName2)(PORT=port)))(CONNECT_DATA=(SERVICE_NAME=ServiceName)))'
pds.setURL(dbURL)
More information: Configuring Fast Connection Failover for JDBC Clients
It appears to be working with a connection string containing only host 1.
The Database URL is in the form:
jdbc:oracle:thin:#<hostname>:<port>/<serviceName>
Additionally, I got the error because the .jar file's path was not added to the classpath (click on Test Plan, in the bottom select browse next to Add directory or jar to classpath and select your odbc jar).
Another thing that was wrong was the Validation query, it should be "select 1 from dual" and also the query should not contain any semicolon at the end.
I hope this help people with the same issue.

Node-odbc unable to connect to mssql

I've spent the last day or two setting up unixODBC and freetds on ubuntu 12 - not a fun process in itself but it does now work using both sqsh and isql. I've installed node-odbc and I'm using the code snippet provided in the github readme to test the connection but I always get
S1000:1:0:[unixODBC][FreeTDS][SQL Server]Unable to connect to data source
WARNING: ev_unref is deprecated, use uv_unref
[Error: Error opening database]
Using isql I run isql -v SERVER user pass (using the correct creds..) and then use DATABASE once connected and it all works and I can run queries fine. My connection string in the js is
"DRIVER={FreeTDS};SERVER=SERVER;UID=user;PWD=pass;DATABASE=DATABASE"
Which exactly matches the credentials used for connecting with isql but in Node I get the aforementioned error. Any ideas on why this is happening? Is it possible that it's to do the location of my odbc.ini and odbcinst.ini files or something like that?
Just for reference:
/etc/odbc.ini:
[SERVER]
Driver = FreeTDS
Trace = No
Server = SERVER
Port = 1433
Database = DATABASE
UsageCount = 1
TDS_Version = 7.0
/etc/odbcinst.ini:
[FreeTDS]
Description = FreeTDS
Driver = /usr/lib/libtdsodbc.so
Setup = /usr/lib/libtdsS.so
FileUsage = 1
CPTimeout = 5
CPReuse = 20
Threading = 1
Thanks in advance for any help!
Ran into this problem today, it ended up being that I needed to specify a port number as part of the connection string. FYI.
It looks like I have just found a solution to this although I don't fully understand why. If the connection string used is:
"DRIVER={FreeTDS};SERVER=SERVER;UID=user;PWD=pass;DATABASE=DATABASE"
Then for some reason it doesn't work at all, I've tried using setting SERVER as both the IP and the actual name of the machine...no luck. However if I change the connection string to use SERVERNAME or DSN (can only have one of SERVER, SERVERNAME or DNS in the string) and I supply the machine name then it works fine, I can't get it to work with IP no matter what I try though. So, in summary the connection string that is working for me is:
"DRIVER={FreeTDS};SERVERNAME=SERVERNAME;UID=user;PWD=pass;DATABASE=DATABASE"
The key to this problem seems to lie in SQLDriverConnect.

How to Connect R to Oracle?

I need to connect R to oracle and I have been unsuccessful so far. I downloaded two packages: RODBC & RODM.
This is the statement that I've been using:
DB <- odbcDriverConnect("DBIORES1",uid="mhala",pwd="XXXXXXX")
But I get this error:
Error in odbcDriverConnect("DBIORES1", uid = "mhalagan", pwd = "XXXXXXX") :
unused argument(s) (uid = "mhalagan", pwd = "XXXXXXX")
What information do I need to be able to connect to an oracle database? Am I using the correct package?
See the help page for odbcDriverConnect(). odbcDriverConnect() does not accept uid or pwd arguments. You probably meant to use odbcConnect() instead:
odbcConnect(dsn = "DBIORES1", uid = "mhala", pwd = "XXXXXXX")
In addition to the RODBC package, there is the RODM package, which I believe is specifically designed for Oracle databases and is further described here: http://www.oracle.com/technetwork/articles/datawarehouse/saternos-r-161569.html . I do not use Oracle databases, so cannot comment on advantages of the two packages.
RJDBC worked just fine for me. You just need to have Oracle-thin driver jar file and configure the connection like:
> install.packages("RJDBC")
> library(RJDBC)
> drv <- JDBC("oracle.jdbc.driver.OracleDriver","/path/to/driver/com/oracle/oracle-thin/11.2.0.1.0/oracle-thin-11.2.0.1.0.jar”)
> conn <- dbConnect(drv, "jdbc:oracle:thin:#database:port:schema”, “user”, “passwd”)
and then is ready to perform some queries.
JA.
I've had success in the past connecting to Oracle databases from R with RJDBC. I found it easier to get going as I just grabbed the connection string that I'd used successfully inside the java based GUI I was using at the time and like magic it "just works"(tm).
Did you install the oracle ODBC client/driver? You will need that if you are going to use the ODBC R package. Go to oracle instant client download get the client for your OS. install them and then proceed to configure the ODBC and test the connection outside of R then install the R and RODBC and test inside R.

Resources