Can I set Kusto cluster from config file? - azure-data-explorer

Does anybody have experience with setting the cluster name in a Kusto query from a config file? For example,
cluster(Config.clusterName).database('sample').MyTable
Or is the cluster name always hard-coded? Any help is much appreciated!

The syntax you are using is "cross cluster query" meaning you can run it when connecting you another cluster. If you don't need specifically this syntax, you can read the connectionstring where you are running the query from config file, for example:
var serviceUri = Config.clusterUri
var authority = "contoso.com"; // Or the AAD tenant GUID: "..."
// Recommended syntax
var kustoConnectionStringBuilder = new KustoConnectionStringBuilder(serviceUri)
.WithAadUserPromptAuthentication(authority);
If you need the cross cluster query and want to read the connection string from config file, you can add the query with some template to replace (like {0}) and replace it using string.format for instance before running the query
MyQuery join (cluster({0}).database('sample').MyTable)

The cluster name must be a constant string, for security reasons.

Related

specify a database name in databricks sql connection parameters

I am using airflow 2.0.2 to connect with databricks using the airflow-databricks-operator. The SQL Operator doesn't let me specify the database where the query should be executed, so I have to prefix the table_name with database_name. I tried reading through the doc of databricks-sql-connector as well here -- https://docs.databricks.com/dev-tools/python-sql-connector.html and still couldn't figure out if I could give the database name as a parameter in the connection string itself.
I tried setting database/schema/namespace in the **kwargs, but no luck. The query executor keeps saying that the table not found, because the query keeps getting executed in the default database.
Right now it's not supported - primarily reason is that if you have multiple statements then connector could reconnect between their execution, and result of use will be lost. databricks-sql-connector also doesn't allow setting of the default database.
Right now you can workaround that by adding explicit use <database> statement into a list of SQLs to execute (the sql parameter could be a list of strings, not only string).
P.S. I'll look, maybe I'll add setting of the default catalog/database in the next versions

How to get DynamoDB from DynamoDB local creation

Trying to write integration test for my logic, using recommended way to launch dynamoDB local:
final String port = getAvailablePort();
this.server = ServerRunner.createServerFromCommandLineArgs(new String[] { "-inMemory", "-port", port });
server.start();
amazonDynamoDB = AmazonDynamoDBClientBuilder.standard().withEndpointConfiguration(
// we can use any region here
new AwsClientBuilder.EndpointConfiguration("http://localhost:" + port, "us-west-2")).build();
I am planning to use com.amazonaws.services.dynamodbv2.document.DynamoDB in my production code to read/write from dynamo. I am looking to reuse some production dynamo-write code to setup testing data, hence, I will need com.amazonaws.services.dynamodbv2.document.DynamoDB object. However dynamo local setup above only give com.amazonaws.services.dynamodbv2.AmazonDynamoDB, any clue/suggestion on how to convert?
You can create an instance of DynamoDB from a AmazonDynamoDB using this constructor which has a signature of DynamoDB(AmazonDynamoDB client).

Saving SQLite to Documents Folder

I need to pick an underlying method of saving data collected in the field (offline and remote locations). I want to use the HTML5 Database with SQLite but I can I pick the location? So far, I haven't been able to accomplish that. Here is some sample code I was using:
var dbName = "";
var Dir = blackberry.io.dir;
var path = Dir.appDirs.shared.documents.path;
dbName = path + "/" + "databasetest.db";
var db = openDatabase(dbName, '1.0', 'Test', 50 * 1024);
I used an "alert()" to see the file was "supposedly" created, but when I opened the folder in Explorer I cannot find it. Not really sure why and hense my question.
My application is for data entry, without getting into specifics, user may end up collecting a lot or little data. But I want some way of downloading the SQLite database?
Is this the intention of the SQLite database, or will I have to use another solution?
Thanks!
Chris
The Web SQL Database specification was designed for browsers where it would not have been appropriate to allow web pages to access arbitrary file paths.
The intended way to download data is to upload it to a web server in the cloud.
If you want to know the file name of your database, try executing the PRAGMA database_list. (Whether your app can access that path is a different question.)

LINQ to SQL over multiple databases - Failover Partner?

I have an ASP.NET site using LINQ to SQL set up with multiple databases (by changing the Source for the tables on the other/"secondary" server). As seen here.
How do I set up a Failover Partner for this? I have it set up in the connection string, but I had to hardcode the Source with the server name, so that doesn't work.
The best method I could find/come up with was to create two LINQ External Mappings. On startup, I check to see if the main server is running using the main Mapping. If it's not, I set my connections to use the second LINQ mapping that has the FailOver database:
var xmlPath = #"C:\myAppFailOver.map";
System.Data.Linq.Mapping.XmlMappingSource linqMapping = System.Data.Linq.Mapping.XmlMappingSource.FromReader(System.Xml.XmlReader.Create(xmlPath));
using (DataClassesDataContext db = new DataClassesDataContext(connString, linqMapping))
{
//code
}

Constructing the Connection String for the DataContext Class

I see a couple of DataContext connection string questions. I'm going to try to differentiate this one a bit:
How does one construct a generic connection string to a database, localhost | User-PC\User | Some database... (it is hosted/managed by Microsoft SQL 2008)
I notice that it is IDisposable. So if I have multiple users hitting my site, my code can only access the database one instance at a time, and has to wait until each instance is disposed, in order for the data to be consistent for each user?
Is it possible, by any chance, to somehow enable LINQ in F#-Interactive, and connect to the database from there? I cannot figure out how to enable/load the System.Data dll into fsi. Maybe that is unique to my installation, or it is a common thread? (ie, my installation also does not recognize windows.base.dll--I have to manually get it from programs\reference assemblies).
Anyhow, I've pretty much conclusively discovered that
let x = new System.Data.Linq.DataContext("localhost")
...does not work.
1) How does one construct a generic connection string to a database?
There is no generic way to construct a connection string. The best thing to do is to keep the connection string in some configuration file where you can change it depending on your configuration (the name of SQL Server machine, authentication options, whether it is a file-based database or normal). There is a web site with examples for most of the options.
2) I notice that it is IDisposable. So if I have multiple users hitting my site, my code can only access the database one instance at a time [...]?
No, this is not how DataContext works. The DataContext does not keep a live connection to the server that would block anybody else from using the SQL server. It keeps some state (i.e. cached entities that were already obtained) and it uses optimistic concurrency to make sure that the state is consistent (you can use transactions to prevent other connections, if that's what you want).
3) Is it possible, by any chance, to somehow enable LINQ in F#-Interactive [...]?
That shouldn't be a problem. You can reference assemblies using #r "foo.dll" in F# interactive. The typical approach for F# 2.0 is to generate the data context using C# tools and then just reference it (for F# 3.0, things are easier because you can just use type provider).
If you generate LINQ to SQL data context for Northwind in C#, the F# Interactive use would look like this:
#r #"<whatever_path>\Northwind.dll"
#r "System.Data.Linq.dll"
open Northwind
open Microsoft.FSharp.Linq
let connStr = #"Data Source=.\SQLEXPRESS;AttachDbFilename=<path>\NORTHWND.MDF;" +
#"Integrated Security=True;User Instance=True"
let operation () =
// Using 'use' to make sure it gets disposed at the end
use db = new NorthwindDataContext(connStr)
// do something with the database
There actually is a somewhat generic way to construct a connection string:
open System.Data.Common
open System.Data.SqlClient
let providerName = "System.Data.SqlClient"
let factory = DbProviderFactories.GetFactory(providerName)
let cnBuilder = factory.CreateConnectionStringBuilder() :?> SqlConnectionStringBuilder
cnBuilder.DataSource <- "localhost"
cnBuilder.InitialCatalog <- "MyDatabase"
cnBuilder.IntegratedSecurity <- true
let connStr = cnBuilder.ConnectionString
My approach was to have 1 connection string and then use that for all of my DataContext connections. So this code builds the EntityConnectionString based on MyConnString:
protected override MyEntities CreateObjectContext()
{
string ConnString =ConfigurationManager.ConnectionStrings["MyConnString"];
string seConn = ConfigurationManager.ConnectionStrings["MyEntities"].ToString();
EntityConnectionStringBuilder ecsb = new EntityConnectionStringBuilder(seConn);
ecsb.ProviderConnectionString = ConnString;
EntityConnection ec = new EntityConnection(ecsb.ToString());
ScheduleEntities ctx = new ScheduleEntities(ec);
return ctx;
}

Resources