RavenDB Embedded in the Cloud - ravendb

Can you embed a RavenDB database in an MVC application that is hosted on Azure.
Ideally one could still access the management studio as well.
Thanks

I'm attaching here the answer from the support email.
Yes, you can. Here are the steps:
Download the https://www.nuget.org/packages/RavenDB.Database/3.0.30115 package
Setup like this:
var store = new EmbeddableDocumentStore
{
DataDirectory = "Data",
UseEmbeddedHttpServer = true,
Url = "http://localhsot:8080",
};
Make sure to open the port in the firewall on Azure.
Access the studio using the server IP and port, as 11.22.33.44:8080

Yes, that is possible.
Note that this require a license.

Related

What is the correct Cloud SQL connection string syntax for dotnetcore app with Cloud Run?

I want to setup a .NET Core web application on Cloud Run with a Google Cloud SQL database. I easily deployed the database which has a public IP on Cloud SQL and my web application with Docker Container on Cloud Run. I can access the database with SQL Server Management Studio without any difficulties and the web app is up and running as expected. The only piece missing is the link between them that allows them to connect.
In my web app, I got a connection string in that format :
Data Source=***;Initial Catalog=***;User ID=***;Password=***;Pooling=true;Trusted_Connection=false;Connection Timeout=60;Integrated Security=false;Persist Security Info={0};Encrypt=true;TrustServerCertificate=true;MultipleActiveResultSets=true;
Once I got the public IP and the connection name from Cloud SQL, how should be precisely be the connection string and/or the next steps?
Furthermore, in the connections tab under Cloud Run Service, I added the Cloud SQL connection. This is supposed to configure a Cloud SQL Proxy for me.
In order to connect to Cloud SQL from Cloud Run, you must follow this guide
You have already made some configurations in the Connections tab as stated in the Configuring Cloud Run section. You can check the guide for the Public IP since you configured your instance that way, to be sure that all steps were followed.
Briefly, the steps are:
Configure the service account for your service. Make sure that the service account has the appropriate Cloud SQL roles and permissions to connect to Cloud SQL.
The service account for your service needs one of the following IAM roles:
Cloud SQL Client (preferred)
Cloud SQL Admin
If the authorizing service account belongs to a different project than the Cloud SQL instance, the Cloud SQL Admin API and IAM permissions will need to be added for both projects.
Like any configuration change, setting a new configuration for the Cloud SQL connection leads to the creation of a new Cloud Run revision. Subsequent revisions will also automatically get this Cloud SQL connection, unless you make explicit updates to change it.
Go to Cloud Run
Configure the service:
If you are adding Cloud SQL connections to an existing service:
Click on the service name.
Click on the Connections tab.
Click Deploy.
Enable connecting to a Cloud SQL instance:
Click Advanced Settings.
Click on the Connections tab.
If you are adding a connection to a Cloud SQL instance in your project, select the desired Cloud SQL instance from the dropdown menu.
If you are deleting a connection, hover your cursor to the right of the connection to display the Trash icon, and click it.
Click Create or Deploy.
After you've double checked the steps above, you could continue with the section Connecting to Cloud SQL. You can follow the steps on the Public IP tab.
Connect with Unix sockets
Once correctly configured, you can connect your service to your Cloud SQL instance's Unix domain socket accessed on the environment's filesystem at the following path: /cloudsql/INSTANCE_CONNECTION_NAME.
The INSTANCE_CONNECTION_NAME can be found on the Overview page for your instance in the Google Cloud Console or by running the following command:
gcloud sql instances describe [INSTANCE_NAME].
These connections are automatically encrypted without any additional configuration.
The code samples shown below are extracts from more complete examples on the GitHub site. To see this snippet in the context of a web application, view the README on GitHub.
// Equivalent connection string:
// "Server=<dbSocketDir>/<INSTANCE_CONNECTION_NAME>;Uid=<DB_USER>;Pwd=<DB_PASS>;Database=<DB_NAME>;Protocol=unix"
String dbSocketDir = Environment.GetEnvironmentVariable("DB_SOCKET_PATH") ?? "/cloudsql";
String instanceConnectionName = Environment.GetEnvironmentVariable("INSTANCE_CONNECTION_NAME");
var connectionString = new MySqlConnectionStringBuilder()
{
// The Cloud SQL proxy provides encryption between the proxy and instance.
SslMode = MySqlSslMode.None,
// Remember - storing secrets in plain text is potentially unsafe. Consider using
// something like https://cloud.google.com/secret-manager/docs/overview to help keep
// secrets secret.
Server = String.Format("{0}/{1}", dbSocketDir, instanceConnectionName),
UserID = Environment.GetEnvironmentVariable("DB_USER"), // e.g. 'my-db-user
Password = Environment.GetEnvironmentVariable("DB_PASS"), // e.g. 'my-db-password'
Database = Environment.GetEnvironmentVariable("DB_NAME"), // e.g. 'my-database'
ConnectionProtocol = MySqlConnectionProtocol.UnixSocket
};
connectionString.Pooling = true;
// Specify additional properties here.
return connectionString;
Google recommends that you use Secret Manager to store sensitive information such as SQL credentials. You can pass secrets as environment variables or mount as a volume with Cloud Run.
After creating a secret in Secret Manager, update an existing service, with the following command:
gcloud run services update SERVICE_NAME \
--add-cloudsql-instances=INSTANCE_CONNECTION_NAME
--update-env-vars=INSTANCE_CONNECTION_NAME=INSTANCE_CONNECTION_NAME_SECRET \
--update-secrets=DB_USER=DB_USER_SECRET:latest \
--update-secrets=DB_PASS=DB_PASS_SECRET:latest \
--update-secrets=DB_NAME=DB_NAME_SECRET:latest
See also:
GoogleCloudPlatform/dotnet-docs-samples on GitHub

Discord.js Database

I have made a bot called "Hello Bot" but I want to have a database connection so I can do more things but I can not find a way to do it on will you help me?
You can use something like SQLite or Enmap depending on what you're trying to do. You could also link into MySQL by running npm install mysql in your bot's directory and adding the following code at the top of your bot's js file:
const mysql = require('mysql');
const connection = mysql.createConnection({
host : 'hostname',
port : 'portnum',
user : 'db_user',
password : 'db_user_password',
database : 'db_name',
charset : 'utf8mb4'
});
Note that you will have to install and setup MySQL on your server and create your database.
Here are a couple more links regarding setting my Node.js with Database access:
https://hackernoon.com/setting-up-node-js-with-a-database-part-1-3f2461bdd77f
https://tr-center.com/line/discord-js-bot-tutorial-part-6-xp-system-with-mysql-E5TVwyiCuYA.html
I'm a little late to the game on this one. But what I did with mine is used a atlas mongodb. I have my bot hosted on Amazon's AWS so connecting to a cloud DB was pretty easy from a nodejs project.

Access network share from IIS hosted WCF web service

I have a C# WCF web service hosted by IIS7 running on Windows Server 2008 R2. My web service needs to access a network share and so during Application_Start I execute the following:
NETRESOURE nr = new NETRESOURCE();
nr.dwScope = RESOURCETYPE_DISK;
nr.lpRemoteName = string.Format(#"\\{0}\{1}", MyServer, MyShareName);
nr.lpLocalName = #"X:";
string UserName = MyWebSvcLoginName;
string Password = MyWebSvcPassword;
uint result = WNetAddConnection2(ref nr, Password, UserName, CONNECT_UPDATE_PROFILE);
This has been working fine for 3 months. All of the threads in the web service process had access to the mapped drive. Now, all of a sudden, only the thread that called WNetAddConnection2 has the drive mapped. I am not aware of anything that changed in the server configuration. Are there any options that would prevent other threads in the process from seeing the mapped drive?
You need to look for the difference between what works and what does not. Things to check are:
Does the one that works running in a different application pool with a different identity. Has the identity that does not work lost some rights?
Does the one that works use a different user name and password to access the share. Has the passord of the user that does not work expired?
Do all map to the same drive letter? Is the drive being used for another share?

Is there a visual tool to view a RavenDB database?

I just got RavenDB to work.
I realised I have to start RavenDB\packages\RavenDB.1.0.573\server.exe to access it in my application via:
DocumentStore store = new DocumentStore()
{
Url = "http://localhost:8080"
};
store.Initialize();
Is there a tool to view the data in the database similar to SQL Server Management Studio?
Run the server and access it using the browser, you'll get the buil-in RavenDB management Studio
http://ravendb.net/docs/intro/basic-concepts#the-management-studio
There are two products at the time of this answer
The built in web browser, as #synhershko answered.
LinqPad with the RavenDb driver.

Is it possible to connect to an embedded DB with Raven Management Studio

I'm playing with Raven DB and am wondering if it's possible to connect to an embedded DB with Raven Management Studio. Has anyone ever done this?
If I understood you correct and you mean the Web UI, you simply have to enable the embedded web server.
var documentStore = new EmbeddableDocumentStore
{
DataDirectory = "Data",
UseEmbeddedHttpServer = true
};
See http://ravendb.net/docs/server/deployment/embedded
Also make sure to include Raven.Studio.xap in the root of your web application