Posts in Category: data

Connecting to Azure Db via Code

Getting started with a new platform can be a little daunting, after all, there is so much to learn and where do you start.

From a client-side perspective, the only difference in connecting to an Azure Db over a server Db is the connection string.

string connectionstring = "Server=tcp:#SERVER#,1433;Initial Catalog=Signal;PersistSecurityInfo=False;User ID=#USERNAME#;Password=#PASSWORD#;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30";

SqlConnection cn = new SqlConnection();
cn.ConnectionString = connectionstring;

cn.Open();

From there, it’s a simple job of opening a connection, creating a command and querying your data.

The biggest problem I ran into was having to create the firewall rule to allow access (this will not be enabled by default).  Thankfully Visual Studio took care of this, giving me the prompt to do so and quickly enable.

firewall.pngRead More


Creating you First Azure Database

If you’re still creating databases locally for all your development and testing needs, it’s time to give yourself the kick you need to start doing things a little differently and learn something new in the process.

Going to Azure isn’t as complicated as you think (if you start small).  If you’re worried about costs, there are tons of credits floating around to make the learning cycle quick and painless.

First, setup a Resource Group, for a listing of all Azure related terminology, check here.  When you’re done doing this, navigate down to SQL Databases and create a database server (a URL) and whatever associated database you want to go along with it.

In my portal view, this looks a little like this where I now have a server and a database.

Read More


Dynamics365 Alternate Keys and UpSert

Using Alternate keys is an easy way to stop doing pre and post checks for whether you can insert data into Dynamics.

Before you had to do a check behind the scenes for whether an “Id” existed and if not go and insert it.

Now using the “Upsert” pattern in Dynamics, you can accomplish this task in one method call using an alternate key.

At’s it’s most simplest implementation, I created a custom entity and a field (wholenumber) that I then declared as my alternate key.

altdesign.PNG

Then I wrote the following code to insert the following record into my system.  You can

Read More


Keeping your Dynamics365 Audit Logs Tidy

Audits are a great way to see what has happened on records, what they did and more importantly who did it.

But if you have automated processes running that are pumping data into Dynamics because a field or two has changed, you might end up with an Audit History looking something like this.

In this case, an update was triggered, but it wasn’t until the fourth update that there was an actual difference in the data being changed.  Even then, when we sent the whole packet of data, we sent it all.

With only four feels you can already see this gets a little painful to follow.

Capture.PNGRead More


Accessing Data with LiteDb

In my last post I talked about how easy it was to create a database with LiteDb.

But accessing your data is even easier.

To start off, assuming we have no document (i.e., structure) associated with our data – we can create a generic table on the fly using the built in BSonDocument structure.

In this example, I first use my database to get a collection of documents under “FirstTable”.  If it’s your first time creating this document, don’t worry, it’ll be created for you, so no need to do any “CREATE” mumbo jumbo.

var FirstTable = database.GetCollection("FirstTable");

Now I’m going to create some data.  The simplest, most brain-dead way to do this is to create a Dictionary, make some columns and give them whatever values I want that are of type BsonValue

Dictionary<string, BsonValue> docs															

Read More