MongoDB C# driver throws timeout exception when trying to connect to replica set - mongodb-.net-driver

I've had problems connecting to a replica set via the C# sharp driver when using the following code:
var client = new MongoClient("mongodb://daluser:daluatmongo#xxx:25015,yyy:25015,zzz:25015/database?replicaSet=dal_uat_mongo");
var db = client.GetDatabase("database");
var collection = db.GetCollection<BsonDocument>("table");
var foo = collection.CountAsync(document => true).Result;
Here xxx, yyy and zzz are IP addresses and I've used anonymous names for the collection and database.
This results in the following exception: "A timeout occured after 30000ms selecting a server using CompositeServerSelector" (more details in gist link):
https://gist.github.com/bfranklinsportingindex/0270a1e958051b689e56
Strangely if we remove the replica set option and only specify one server then it works fine for two of the three servers. The server that fails gives us the familiar "target machine has refused the connection" error.
I'm currently testing directly with the latest version of the source code and the version of mongo on the server we're tryingt to connect to is 2.6.9
I've tried debugging into the source code for the driver amd I get to the following line in SelectServerAsync method in the Cluster class:
var connectedServers = description.Servers.Where(s => s.State == ServerState.Connected);
Here the connectedServers collection is empty and I would expect (with my limited understanding of driver codebase) it to be populated. Hopefully someone with more experience with this codebase can shed any light on what's going on or provide me with some pointers on where to look in the codebase.

Actually we managed to trace the problem down to a network address translation issue which we tested by putting add some lines to the hosts file. The driver seems to be working fine now.

Related

Mule Connect to remote flat files

I am new to Mule and I have been struggling with a simple issue for a while now. I am trying to connect to flat files (.MDB, .DBF) located on a remote desktop through my Mule application using the generic database connector of Mule. I have tried different things here:
I am using StelsDBF and StelsMDB drivers for the JDBC connectivity. I tried connecting directly using jdbc URL - jdbc:jstels:mdb:host/path
I have also tried to access through FTP by using FileZilla server on remote desktop and using jdbc URL in my app - jdbc:jstels:dbf:ftp://user:password#host:21/path
None of these seem to be working as I am always getting Connection exceptions. If anyone has tried this before, what is the best way to go about it? Connecting a remote flat file with Mule? Your response on this will be greatly appreciated!
If you want to load the contents of the file inside a Mule flow you should use the file or FTP connector, i don't know for sure about your JDBC option.
With the File connector you can access local files (files on the server where mule is running), you could try to mount the folders as a share.
Or run an FTP server like you already tried, that should work.
There is probably an error in your syntax / connection.
Please paste the complete XML of your Mule flow so we can see what you are trying to do.
Your usecase is still not really clear to me, are you really planning to use http to trigger the DB everytime? Anyway did you try putting the file on a local path and use that path in your database url. Here is someone that says he had it working, he created a separate bean.
http://forums.mulesoft.com/questions/6422/setting_property_dynamically_on_jdbcdatasource.html
I think a local path is maybe possible and it's better to test that first.
Also take note of how to refer to a file path, look at the examples for the file connector: https://docs.mulesoft.com/mule-user-guide/v/3.7/file-transport-reference#namespace-and-syntax
If you manage to get it working and you can use the path directly in the JDBC url, you should have a look at the poll scope.
https://docs.mulesoft.com/mule-user-guide/v/3.7/poll-reference
You can use your DB connector as an inbound endpoint when wrapped in a poll scope.
I experienced the same issue when connect to Microsoft Access Database (*.mdb, *.accdb) using Mule Database Connector. After further investigation, it's solved by installing Microsoft Access Database Engine
Another issue, I couldn't pass parameter to construct a query as same as I do for other databases. e.g.: SELECT * FROM emplcopy WHERE id = #[payload.id]
To solve this issue:
I changed the Query type from Parameterized into Dynamic.
I generated the query inside Set Payload transformer (generate the query in form of String, e.g.: SELECT * FROM emplcopy WHERE id = '1').
Finally, put it into the Dynamic query area: #[payload]

Server name dissapears from rdoConnection.Connect string

I'm working with an old Visual Basic 6 application that connects to an Oracle11g server using Remote Data Objects (RDO) 2. Here is my code:
Dim rdoCon As New rdoConnection
rdoCon.Connect = "DRIVER={Microsoft ODBC for Oracle};SERVER=os11atst.world;"
Debug.Print rdoCon.Connect '1
'Prompt the user to enter credentials and connect to the server:
rdoCon.EstablishConnection rdDriverComplete, False
Debug.Print rdoCon.Connect '2
The first Debug.Print gives me this (as expected):
DRIVER={Microsoft ODBC for Oracle};SERVER=os11atst.world;
However, the second one gives me this:
DRIVER={Microsoft ODBC for Oracle};UID=username;PWD=password;
The SERVER parameter is missing, even though the connection works fine. This is a problem for me, because I need to know what server the connection is to. I can not simply use the information from the first string, because the user is (and should be) able to change the server in the prompt that asks for username and password.
This problem arose from nowhere, possibly in connection to an upgrade from Windows XP to 7. Previously the program did not exhibit this behaviour, or so I am told by older colleagues. Not 100% sure that is correct, though.
How can I prevent the dissaperance of the server name? Can I get the name of the server in any other way than looking at the connection string?
I am not interested in solutions that include upgrading to something newer than RDO. For external reasons I am stuck with it.
rdoCon.EstablishConnection will override whatever you had previously set.
It sounds like the problem is in the DSN that is installed on this new machine. Compare it to the DSN that was installed on the previous machine. It had a configuration that you are missing on this new machine.
I have developed a not so pretty workaround to solve this. I have a table called SETTINGS containing columns NAME and VALUE. For every database I have simply added the setting servername together with the appropriate value. All I need to do to find out what server I am connected to is then to query the DB:
SELECT value FROM settings WHERE name = 'servername'
This is of course quite an ugly hack, so any better solutions would be welcome.

what is the GROOVY connection string to an JDBC database with SSPI = True? I am running this from SoapUI Free version

I'm trying to do this:
import groovy.sql.Sql
def sql = Sql.newInstance(
url:'jdbc:sqlserver://localhost\\myDB',
user:'server\user', //this I don't think I need because of SSPI
password:'password',
driver:'com.microsoft.sqlserver.jdbc.SQLServerDriver',
SSPI: 'true'
)
The problem I'm having is that this connection is just timing out. I can ping the machine. I can also connect to the database with Managment Studio logged into my SSPI user (or whatever you call it, I start the Management Studio with a different user)
So I've tried that with my SoapUI as well, started the program as a different user, but I still time out when I initiate the connection. So something is very wrong with my connection string and any help would be appreciated.
P.S. Yes, I don't know what's up with the \ backslashes after the URL to the server, I guess it indicates that it's at the root. If I don't use them I get a message that I'm on the incorrect version.
And then we found the answer..... First of all I had the wrong JDBC driver installed. You need to head over to microsoft to get the real deal:
https://www.microsoft.com/en-us/download/details.aspx?id=11774
Then you need to unpack this one, place the 4 or 4.1 version in your bin directory of SoapUI. (You are apparently supposed to use Lib/Ext, but that doesn't work for me)
Then, since we are trying to use SSPI or Windows Authentication, to connect to the SQL server, you need to place the sqljdbc_auth.dll from the driver/enu/auth folder. This is used in one of your path's or in SoapUI Lib folder. Remember to use the 32 bit dll for 32 bit SoapUI!!! I did not since my system is 64.....
After this, I used this string, but now you have the setup correct, so it should work fine as long as you remember to start SoapUI up using the correct windows user. (Shif-right click - start as different user - use the same user you have started the SQL server with)
Again, I wasn't completely aware of this from the start (yes, total newbie here) and it failed.
Finally, when you have done all this, this is the string that works - and probably a lot of derivatives since the failing part here were the driver and dll.
def sql =Sql.newInstance("jdbc:sqlserver://localhost;Database=myDB;integratedSecurity=true","com.microsoft.sqlserver.jdbc.SQLServerDriver")

C# mongod- insert fails with "unable to connect to server, attempted to read past the stream"

I am able to create a successful connection to a remote mongodb server and database. When I try and insert the document into a collection I get the following error:
Unable to connect to server xxx.xxx.x.xx:28017: Attempted to read past the end of the stream..
after a little lag. I am not sure what the issue is if the connection seems fine.
server = New MongoClient("mongodb://admin:password#xxx.xxx.x.xx:28017/").GetServer
db = server.GetDatabase("TestDB")
mongoC = db("TestCpo")
Have you made sure that Mongo is up and running? Open up a command line, navigate to the location of your mongo installation then to the bin directory, type in "mongod". This will start up the mongo server, you need to have the mongo server up and running before you can do anything with it.
It's also useful to add the path to your environment variables so that it can be set up easier.
Another thing you could do is use
Process.Start(#"C:\[Directory of the mongo installation]\bin\mongod.exe");
(this is probably more useful if you want to start Mongo under test conditions)

JDBC URL for Oracle XA client

Using the JDBC driver oracle.jdbc.xa.client.OracleXADataSource, what is the correct format of the JDBC URL? The thin format of
jdbc:oracle:thin:#host:port:sid
does not work. WebSphere is reporting that the given url (which is otherwise correct) is invalid.
The test connection operation failed for data source Oracle MyDB (XA) on
server nodeagent at node MY_node with the following exception:
java.sql.SQLException: Invalid Oracle URL specifiedDSRA0010E: SQL State = 99999,
Error Code = 17,067. View JVM logs for further details.
There is nothing in the JVM logs.
Whether you use a XA Driver or not, the JDBC connection string is the same (and the format of your question is correct).
For me the issue resolved by adding alias name, username and password in JAAS - J2C authentication data. And also selecting this entry as Component-managed authentication alias.
In case this happens to anyone else. The problem went away after restarting websphere.
In my case, the problem went away when I change the authentication property of the jdbc resource reference from Authentication=Application to Authentication=Container
Had the same issue. Dont know about simple deployments, but on a two nodes cluster, I restarted the first node, and the connection started working on it (not on the second). Restarted the second node, and the connection started working there too.
So just restart the nodes (I also restarted the nodeAgents, but i don't know if it's necessary).
if you are doing using wsadmin command then you need to stop manager,stop node,start manager, sync node and then start node (I mean full sync). Hopefully this will resolve the issue. I dont know why but this resolves my issue.

Resources