Connect Visual Studio with remotely Cassandra server - c#

I'm trying to connect Visual Studio C# code with a Cassandra server
The code works fine in localhost, but I want to connect code to make the change directly on the server. I found instructions to edit a cassandra.ymal file like
listen_address
or
start_rpc
or
rpc_address
Note:
I open a Firewall on a specific port like 9042
I used telnet command to test IP and port is open

I found the solution, i searched a lot, so i found this, that help me, hope it will help others.
1 ) Install Cassandra Workbench
2 ) Update .cassandraWorkbench.jsonc like below snippet
//PasswordAuthenticator
{
"name": "Cluster PasswordAuthenticator", // auth methods
"contactPoints": ["xxx.xxx.xx.x", "xxx.xxx.xx.x"], // seed_provider -> seeds from your cassandra.yml
"hosts": ["xxx.xxx.xx.x"], // your host address
"authProvider": {
"class": "PasswordAuthenticator",
"username": "abc", // host username
"password": "****" // host password
}
}

Related

.Net Core app: Unable to connect to Cassandra 1 node server from a remote PC

I have 1 node test Cassandra claster (IP 192.168.108.198). In Cassandra.yaml listen_address: localhost.
I can connect to it via DBeaver (using ssh port forwarding ), and work in it.
I wrote .net app for using it, but it cant connect to cassandra: "All hosts tried for query failed (tried 192.168.108.198:9042: SocketException". It happens on the last row, as below. Is it problem with cassandra config or my app?
_connectionConfig = connectionConfig;
_socketOptions = new SocketOptions();
_socketOptions.SetReadTimeoutMillis(90000);
_cluster = Cluster.Builder()
.WithPort(_connectionConfig.ConnectionPort)
.AddContactPoints(_connectionConfig.ConnectionStrings)
.WithSocketOptions(_socketOptions)
.WithQueryOptions(new QueryOptions().SetConsistencyLevel(ConsistencyLevel.One))
.WithAuthProvider(new PlainTextAuthProvider(_connectionConfig.UserName, _connectionConfig.UserPassword))
.Build();
_session = _cluster.Connect(_connectionConfig.KeySpaceName);
So, i corrected some settings in Cassandra.yaml, and now connection is going fine, appender other problems, but right settings are:
- class_name: org.apache.cassandra.locator.SimpleSeedProvider
parameters:
# seeds is actually a comma-delimited list of addresses.
# Ex: "<ip1>,<ip2>,<ip3>"
- seeds: "192.168.108.198"
listen_address: 192.168.108.198
rpc_address: 192.168.108.198
192.168.108.198 - Cassandra IP.

Sync gateway is not syncing with Couchbase server in Xamarin

I am trying to use couchbase for online and offline database in my xamarin application .
the offline part is working good , but it doesn't sync .
I followed this tutorial :
https://docs.couchbase.com/userprofile-couchbase-mobile/sync/userprofile/xamarin/userprofile_sync.html
I have installed couchbase server , I created a bucket named : userprofile , and a user and I have enabled the Application Access and Read Only Admin roles.
also I installed sync gateway and I have configured it ,
here is my configuration .json file
{
"log": ["*"],
"databases": {
"userprofile": {
"server": "http://127.0.0.1:8091",
"bucket": "user-profile",
"username": "Maria",
"password": "123456",
"enable_shared_bucket_access": true,
"import_docs": true,
"num_index_replicas": 0,
"delta_sync" :{"enabled":true},
"users": {
"Maria": { "password": "123456"},
"GUEST": { "disabled": false, "admin_channels": ["*"] }
},
"sync": `function (doc, oldDoc) {
if (doc.sdk) {
channel(doc.sdk);
}
}`
}
}
}
and I used this command to configure the sync gateway :
C:\Program Files\Couchbase\Sync Gateway\sync_gateway sync-gateway-config-userprofile-walrus.json
also I have changed the sync url to ws://10.0.2.2:4984 because I am using android emulator .
but it did not sync between devices , can anyone help me please ?
1) How are you verifying if the sync is working (what steps did you follow for testing)? If you are following the instructions here, that won't work with the config you have above. Because the only valid user that you have configured in your config file is the one with credentials "username" and "password" and the steps in tutorial indicates a different username/password. So make sure you log into your app with the credentials you have in your config file and try out
2) You indicated that you have a Couchbase Server running that you have configured for Sync Gateway access. But your config file indicates that you are using "walrus" mode (Walrus mode is a memory only mode intended only for dev/test purposes). In other words, in walrus mode, you are not pointing to an actual couchbase server.
If you want to sync with a backend Couchbase Server(which you should), then replace the "walrus:" in the "server" property in the config file to point to the couchbase server.
3) The best resource to troubleshoot is the Sync Gateway logs. That should give sufficient hints as to what is going wrong with the sync. Post the errors you are seeing if any if the above tips don't work
4) Check out this tutorial for relevant background. Probably from this point

Web-Api dontnet core 2.2 running on centos 7 mysql not working

I built this creating-web-apis-using-asp-net-and-mysql-in-5-minutes
The api runs fine on my local machine windows 10 with visual studio 2017 enterprise. I have a centos box running on VMware in another location this is where my MySQL database is. When I run the api on my local machine I use a connection string with a FQDN and the api runs fine. FYI the api also has a method without database access that basically sends back a json string ["value1","value2"] both this and the one that gets a user from MySQL work fine on local machine.
Next I set it up as a service on the Centos box and set up apache to proxy to the kestrel web server at localhost:5000 using these instructions Host ASP.NET Core on Linux with Apache. my Apache virtual host config is the same as the one in the example except no server alias and no logging. I didn't want a server alias and the logging commands stopped the service from starting. I also needed to upgrade apache from the Centos's repo apache 2.4.6 to Apache 2.4.36 I think.
I did this using a third party repo because RequestHeader set "X-Forward-Proto" expr=%{REQUEST SCHEME} needed Apache 2.4.10 or above.
It should be stated that I used my own database and not the example one it is basic just returns user info like uname etc.
If I run http://MyFQDN/api/values I get the desired response.
If run http://MyFQDN/api/users/1 which when run on my local machine while debugging returns a json string with the correct information using a MySQL connection string with a FQDN and not localhost:3306 or 127.0.0.1:3306 as the server in the connection string. When I try it on the Linux box no go.
Instead I get the infamous http 500 error which I believe means that program is not running correctly the only difference here is the MySQL connection string or there is something else.
in the demo it says
Some values (for example, SQL connection strings) must be escaped for the configuration providers to read the environment variables. Use the following command to generate a properly escaped value for use in the configuration file
However I have tried several times using the example
systemd-escape … see demo for exact syntax as it doesn't escape well here funny.
I believe if I had a properly escaped MySQL connection string that would work on kestrel in the Centos box it might work.
This is in appsettings.production.json
"ConnectionStrings": {
"DevDatabase": "Server=127.0.0.1;Port=3306;Database=nameOfDatabase;Uid=svcuser;Pwd=Password;"
},
Any help would be appreciated
Thanks
________--------UPDATE
So I am trying to attach the visual studio debugger to the web-api using ssh which I believe should let me walk through the code while it is running on the Centos box and find the error.
Here is link to instructions to do just that (FYI no luck yet) Link to instructions
Any advice on this or some other help always accepted
Thanks
use the instructions under my update. I am now able to run the web-api on the Linux box through any browser and step through the code on my machine …….
I have a null object at my connection string from the .json file.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<sPPContext>(options =>
options.UseMySQL(Configuration.GetConnectionString("changedButFrom.json")));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders =
ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
});
}
the error happens on the line where I put changedButFrom.json I am confident it is the escaping of the connection string that is causing the problem before I wasn't sure what the problem was
Great tool

Bot framework emulator not working

I started learning bot framework last week, and i decided to start off with the default bot project that returns your input and its number of character. But unfortunately, I couldn't test the bot application in bot emulator. It can't just send my input. It displays "couldn't send" whenever I forward an input.
My endpoint url which is http://localhost:3979/api/messages/ is correctly written there.
What could be wrong? I'm just a starter in bot framework and bot building.
As I'm not aware of the exact code which you are trying to execute, I'd suggest few points to be checked again.
Checkpoints:
Make sure you are running the code in debug mode with any browser (Edge, chrome, explorer etc.) and then run in the emulator.
Configure or link the emulator with ngrok. (Though it is not required when running locally but it may resolve if the emulator is not working with firewall issues)
Please check the Microsoft App Id and Microsoft App Password are the same in emulator and Web.config file.
Try with blank Microsoft App Id and Microsoft App Password in both Web.config file and emulator.
Check if the endpoints on the browser and emulator are the same
If you are encountering other errors like 401, 405, 500 please check this article.
In case if all the check points are right and you are still encountering an issue while running the code in emulator, there might be an issue with the code or reference libraries. You can also check the working example.
Check your visual studio .bot file. It should be like this.......
{
"name": "EmulatorBot",
"description": "",
"services": [
{
"type": "endpoint",[enter image description here][1]
"endpoint": "http://localhost:3978/api/messages",
"name": "EmulatorBot20181123022900",
"id": "25"
}
],
"padlock": "",
"version": "2.0",
"path": "C:\\Users\\suraj.tiwari\\Desktop\\Bot NK\\EmulatorBot\\EmulatorBot.bot",
"overrides": null
}
Add an Endpoint for your bot
Endpoint url : http://localhost:3978/api/messages
Name : EmulatorBot20181123022900

how to access my lan based postgresql db from my website

We have lan based .Net application with Postgresql 8.1 , now i have task to provide interface on website to read and write two tables on LAN based database I don't know where to start Please help me to solve this problem.
Lan: Windows NT 2003
.Net
Postgresql 8.1
Website:
PHP 5.3
Mysql
You need to enable remote connections on Postgres. But be wary of security implications.
Haven't read it all, but this should give you an idea on the steps to take on the server. For the connector, you generally just need to point the connect function at the remote IP.
Here is how to do the trick. Copied from here:
<?php
// Connecting, selecting database
$dbconn = pg_connect("host=localhost dbname=publishing user=www password=foo")
or die('Could not connect: ' . pg_last_error());
// Performing SQL query
$query = 'SELECT * FROM authors';
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
// Printing results in HTML
echo "<table>\n";
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";
// Free resultset
pg_free_result($result);
// Closing connection
pg_close($dbconn);
?>
in the above code, replace localhost by the IP-address of your Postgres host.
On Linux, two files need to be modified to allow connections other than from localhost:
postgresql.conf, change the listen_addresses = "*" to accept connections from anywhere. Then add a line to the pg_hba.conf file to allow access to the database from a particular IP or network. If you are not worried about security, entering:
host all all 192.168.1.0/24 trust
will allow anyone on the 192.168.1.0/24 network access to any database. Obviously this should only be used to test you can reach the database. Constrain this to the web servers IP address and use md5 so encrypted password authentication is used.

Categories