I'm trying to connect Cassandra cluster with cassandra-sharp .Net client driver, but I get an exception "Can't find any valid endpoint". When I execute sample client code as it is on cassandra-sharp github (https://github.com/pchalamet/cassandra-sharp), I get an error on any operation after opening connection to cluster, such as this Execute command:
using (ICluster cluster = ClusterManager.GetCluster("Cassandra"))
{
ICqlCommand cmd = cluster.CreatePocoCommand();
Task t = cmd.Execute("Select * from system_schema.keyspaces").AsFuture();
...}
When I start debugging this line, I see all my endpoints in view of tree ICluster -> SingleConnectionPerEndpointStrategy -> _endpointStrategy -> NearestEndpointStrategy -> bannedEndpoints (with list of my IP-adresses), and 0 endpoints are healthy.
Moreover, when I'm trying to connect to any of my hosts with cqlplus.exe utility (from cassandra-sharp driver binaries), I get same error. With /dbglog flag it shows messages like this:
Creating connection to 192.168.1.3
Readyfying connection for 192.168.1.3
Starting writing frame for stream 127#192.168.1.3
Done writing frame for stream 127#192.168.1.3
Failed building connection System.AggregateException: One or more errors occurred. ---> System.OperationCanceledException: The operation was canceled.
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at CassandraSharp.Transport.LongRunningConnection.ReadifyConnection() in ...\LongRunningConnection.cs:line 444
...
Error creating transport for endpoint 192.168.1.3 : One or more errors occurrd.
... - marking 192.168.1.3 for recovery
Command execution failed with error:
Can't find any valid endpoint
I use latest version of cassandra-sharp driver 3.7.0 and Cassandra version 3.11.0. My App.config file seems like ok. And the code is ideal, so it may be wrong configuration of the cluster. Network is simple with one switch, everything pinged, all Cassandra ports are opened in Windows firewall on the client PC. I can add any needed additional information from the config file cassandra.yaml, f.e. I use PropertyFileSnitch. In cqlsh console everything works fine, nodetool status is Up&Normal.
So is it something wrong with configuration of my cluster or with .Net driver, and how to solve it? Need help of Cassandra specialists. Thank you!
Сassandra-sharp driver haven't been upgraded since Cassandra 2, and at this moment doesn't work with 3+.
This issue was also posted here: https://github.com/pchalamet/cassandra-sharp/issues/92
Related
I'm working on a Docker related application, written in C#, based on Entity Framework.
One of the Docker containers, is the ms-sql-server, which is used for database access.
In order to access the SQL-server, following connectionString is created:
Server=ms-sql-server;Initial Catalog=Ownobjects;User ID=SA;Password=some_password
While performing following source code:
public void InitialiseDatabase(IApplicationBuilder app)
{
using (var context = app.ApplicationServices.GetRequiredService<ApplicationDbContext>())
{
context.Database.EnsureCreated();
...
... I get following Exception:
Microsoft.Data.SqlClient.SqlException: 'A connection was successfully established with the server,
but then an error occurred during the pre-login handshake.
(provider: TCP Provider, error: 35 - An internal exception was caught)'
Inner Exception
AuthenticationException: The remote certificate was rejected
by the provided RemoteCertificateValidationCallback.
According to this similar StackOverflow post, two things might not match: the instance name in the connection string and the expected name from the instance.
Is this true? In that case, where or how can I find both names?
If this is not true, then what might be causing this issue?
Edit:
Some further examination:
In the Logs of the ms-sql-server Docker container, I've found following line:
Server name is 'e614890825ac'.
This is an informational message only.
No user action is required
I've used this entry in the connectionString but then the same Exception is raised, but this time with following Inner Exception::
ExtendedSocketException: Resource temporarily unavailable
Edit2:
Again some further examination:
In the meantime I've discovered that my original servername in the connectionString is correct.
Thanks in advance
I've spent some time solving this message SQL Server Pre-Login Handshake
Solution 1 (Encryption in client container):
Dockerfile client (github issue)
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
# ...
# SQL Server trusted connection problem
RUN sed -i 's/CipherString = DEFAULT#SECLEVEL=2/CipherString = DEFAULT#SECLEVEL=1/g' /etc/ssl/openssl.cnf
# ...
Note: There's no need to change your connection string adding Encrypt=false or anything else with this setting
Note 2: I'have tried to use focal and other linux images and only aspnet:6.0 works with this setting.
Solution 2 (Image version or storage problems):
Change the runtime version of the client container (see github comments)
Replace the binding storage or volume in sql server container. This could be a user access problem.
Note: There are some comments about this github issue
Every time I try to connect to a snowflake database in .NET 6 using the Snowflake.Data NuGet package, I get a timeout after 120 seconds. I've tried it with all correct credentials in the connection string, as well as all incorrect credentials. No matter what the response is the same:
[2022-06-26T21:05:06.742Z] Snowflake.Data.Client.SnowflakeDbException (0x80004005): Error: Snowflake Internal Error: Unable to connect SqlState: 08006, VendorCode: 270001, QueryId:
[2022-06-26T21:05:06.743Z] ---> System.AggregateException: One or more errors occurred. (Error: Request reach its timeout. SqlState: , VendorCode: 270007, QueryId: )
My code setup looks like this to connect:
using (var conn = new SnowflakeDbConnection())
{
conn.ConnectionString = #"
ACCOUNT=<account>;
USER=<user>;
PASSWORD=<password>;
ROLE=<role>;
DB=<db>;
WAREHOUSE=<warehouse>";
_log.Information("Attempting connection to Snowflake...");
await conn.OpenAsync();
...
Every time after attempting to open the connection it hangs for 120 seconds then produces the above error. I've tried async and non-async as well as a bunch of different connection string properties. I also verified I was able to establish an outbound connection to another database with a regular SqlConnection and that worked with no issues. Not sure what could be going wrong.
Also ran the Snowcd connection diagnostic tool as descripted in the docs, results were all passing:
After much trial and error, adding the specific HOST value to the connection string was what fixed it for me. Specifying the full account with region for the ACCOUNT value did not work. Only when done under HOST. Although the GitHub documentation states that HOST is not required, specifying it with the region is the only thing that prevented timeouts on my end.
I am working on a .NET API that runs inside of a docker container. At some point it makes a call to a Python Flask API that is also running in a container.
var response = await httpClient.GetAsync("http://service-name:8000/actual/url")
which then produces the following error:
System.Net.Http.HttpRequestException: Resource temporarily unavailable
---> System.Net.Sockets.SocketException (11): Resource temporarily unavailable
at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken
cancellationToken)
Has anyone had experience with this before and potentially knows a solution? I cant find much on the web about it at all. I have some seen some mentions of the issue potentially being related to the Flask API not using async methods but that doesnt make sense to me.
The Flask API produces the appropriate responses when accessed through a web browser or Postman using localhost:8000/actual/url and the container logs these responses. I have tried using the localhost URL in the .NET API but that does not work either.
If anymore information is needed please leave a comment and I will do my best to update the post quickly.
-- Christie
TLDR
A reason for the "Resource temporarily unavailable" error is when during name resolution the DNS Server responds with RCODE 2 (Server failure).
Long answer
I noticed the same behavior in a dotnet application running in a dotnet runtime alpine docker container. Here are the results of my investigation:
The error message "Resource temporarily unavailable" corresponds to the EAGAIN error code which gets returned by various functions from the C standard library. At first I suspected the connect() function because the C# stack trace indicates the error happening during the ConnectAsync() call of the c# socket. And indeed the EAGAIN error code appears in the man page of connect() with this description: "No more free local ports or insufficient entries in the routing cache".
I simulated a system with depleted local ports and noticed that a different exception gets thrown in that case, which rules out local port availability as a root cause for the original exception. Regarding the other mentioned cause in the man page it turns out that the routing cache was removed from Linux in 2012. commit
I started to look around for EAGAIN in the source of the musl C lib which is used in the dotnet runtime alpine docker container. After a while I finally noticed the gethostbyname2_r function which is used for resolving a domain name to an ip address via DNS. During System.Net.Sockets.Socket.ConnectAsync() the hostname is still a string and the name resolving happens in native code using the gethostbyname2_r function (or one of its variations).
The final question is: When does gethostbyname2_r return the EAGAIN error code? It's when the RCODE field in the header of the DNS Response has the value 2, which stands for "Server failure". source line 166
To verify this result I ran a simple mock DNS server which always returns the RCODE 2 in the DNS response. The resulting c# exception along with the stack trace matched the original exception exactly.
I apologize in beforehand because I see that a lot of people have already answered this question but still I cannot find the answer I am looking for.
In my solution I got 5 projects where 2 are C# libraries (the Core layer and the Data layer). The other 3 are using the Core layer to connect to the data layer and these three are a web-API project, a test winform project and a MVC project. I am currently trying out the winform project and that is where the error occurs. The API project works fine when connecting to database.
As the title suggest I have gotten this common exception in the winform project
System.Data.DataException: 'An exception occurred while initializing
the database. See the InnerException for details.'
EntityException: The underlying provider failed on Open.
with the following inner exceptions
SqlException: Connection Timeout Expired. The timeout period elapsed
while attempting to consume the pre-login handshake acknowledgement.
This could be because the pre-login handshake failed or the server was
unable to respond back in time. The duration spent while attempting
to connect to this server was - [Pre-Login] initialization=38878;
handshake=35;
Win32Exception: The wait operation times out
The errors occurs in my Datacontext on Database.Initialize(true);:
public class DataContext : DbContext
{
public DataContext() : base("HololensRegistreringsskyltar")
{
Database.SetInitializer(new DataContextInitializer<DataContext>());
Database.Initialize(true);
}
}
I am also using generic repository pattern with Unit Of Work if that matters (and I am new to it).
Btw there is only a connection string in the API projects web.config, maybe there should be in the other two "outer" layers too?
Can anyone tell me how to solve this issue and making it work for all 3 "outer" layers?
Following cases can cause this exception:
An instance of the SQL Server Database Engine is not running.
The SQL Server Browser service is not running.
The TCP/IP is disabled.
The server name was typed incorrectly.
There are network problems.
The TCP/IP port for the Database Engine instance is blocked by a firewall.
The client and server are not configured to use the same network protocol.
I am trying to connect to a remote queue using c#.
I tried many ways to connect to the remote queue but it always fails with common errors like: MQRC_CHANNEL_CONFIG_ERROR or MQRC_HOST_NOT_AVAILABLE.
What I am doing is this:
string channel = "QM_TEST.SVRCONN";
string hostname = "<serverIp>";
string queueName = "QM_TEST";
string port = 1414;
props.Add(MQC.HOST_NAME_PROPERTY, hostname);
props.Add(MQC.CHANNEL_PROPERTY, channel);
props.Add(MQC.PORT_PROPERTY, port );
props.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
MQQueueManager mqQueue = new MQQueueManager(queueName, props);
I have tried changing this but all failed.
I think that my problem is the server configurations..
can you point me to a full guide to how to configure a server and connect to it with .net?
My problem is connecting to a REMOTE server using .net and not to a local server.
Thank you!
The problem was that the CCSID between the client and the server were different.
http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0/index.jsp?topic=%2Fcom.ibm.mq.csqzaf.doc%2Fcs12480_.htm
On the client side I had to put
Environment.SetEnvironmentVariable("MQCCSID", "437");
Thats why I got:
MQRC_CHANNEL_CONFIG_ERROR
I'm guessing the problem (or at least a problem) is here:
MQQueue mqQueue = new MQQueueManager(queueName, props);
This should be
queueManager = new MQQueueManager(queueManagerName, properties);
If you have installed the WebSphere MQ client to the default location, there are many sample programs under the following directory:
C:\Program Files (x86)\IBM\WebSphere MQ\tools\dotnet\samples\cs\base\
There are a number of sample programs there for various tasks. If you have the latest V7.1 client installed then you will see the following programs:
SimpleAsyncPut
SimpleClientAutoReconnectGet
SimpleClientAutoReconnectPut
SimpleGet
SimpleMessageProperties
SimplePublish
SimplePut
SimpleReadAhead
SimpleSharingConversation
SimpleSubscribe
SimpleXAGet
SimpleXAPut
There are also WCF and XMS samples.
If you need the client code, please see my response to another SO question here for links.
Update:
Here's the normal diagnostic process.
If the WMQ components were installed by relocating libraries or classes from somewhere else, perform an install using the full vendor-supplied client media. This includes troubleshooting utilities such as trace, dspmqver, etc. It also resolves any library or class mismatch issues.
Use the pre-compiled client programs to test the connection. The amqsputc, amqsgetc and amqsbcgc programs require the MQSERVER environment variable as described here. The Q program from SupportPac MA01 is a separate download but has the advantage of NOT requiring any environment variables, CCDT files or other dependencies.
If the sample programs fail, check the QMgr's error logs at [WMQ install]/qmgrs/[QMgr name]/errors/AMQERR01.LOG for messages. Also check for FDC files and errors in [WMQ install]/errors.
If no errors on the QMgr side, attempt the connection again while using a client-side trace as described here and here.
Most client problems are resolved through installation of the full WMQ client as supplied by IBM. (Conversely that implies most people are installing by grabbing DLL or JAR files.) If the problem persists, error log inspection on the QMgr and client side usually reveals the underlying cause. If these do not work then tracing usually diagnoses the remaining issues.
UPDATE 2:
Per the error messages posted at MQSeries.net, the channel has a security exit set. A security exit is external code that the channel calls out to when starting a channel. There is no way to know what the exit expects or does without having access to the code or docs of the exit. If the exit is written in-house, you'll need to talk to the programmer to figure out what it requires. If the exit is a commercial product then you will need to get the documentation for it.
Alternatively, alter the channel so that SCYEXIT is blank to disable the exit.
The data posted at MQSeries.net was as follows:
MQ9575: DCE Security: failed to get the user's login name.
EXPLANATION:
System call 192.168.50.55 to get the login name of the user running WebSphere
MQ client application process 5 failed with error value -1. This occurred in
security exit function create_cred. The exit will now attempt to open channel
using the DCE default login context.
ACTION:
If you wish to run using the DCE default login context take no action. If you
wish to run using the user's login name as the DCE security exit principal
examine the documentation for the operating system on which you are running MQ
clients and reconfigure the operating system as necessary to allow the
192.168.50.55 call to succeed.
Note that it states the call is failing in the security exit.