Drawing using Spatial Data (Geometry) in T-SQL

Try executing this in SSMS.

You should be able to see an ‘H’ in ‘Spatial results tab’

image

You can find the reference reading here – http://technet.microsoft.com/en-us/library/bb933790.aspx

 

MongoDB C# – for beginners

Assuming you have MongoDB installed and configured already.

You have to download MongoDB C#/.NET Driver also – http://docs.mongodb.org/ecosystem/drivers/csharp/

You will get two dlls which you have to ‘add reference’ to your project.

  • MongoDB.Bson.dll
  • MongoDB.Driver.dll

Add the namespaces to your code first:

using MongoDB.Bson;
using MongoDB.Driver;

Table Structure

Define “table” structure. (I have used ‘table’ term here just to make a similarity with SQL tables. MongoDB as you know is a NoSQL database and the data stored is unstructured.

public class ADVT
{
    [BsonId]
    public ObjectId _Id { get; set; }

    public string advt { get; set; }
    public DateTime date { get; set; }
}

Note the [BsonId] and ObjectId. This is the _id reference in your physical database. You have to use namespace MongoDB.Bson.Serialization.Attributes to make this work.

Physical database looks like this if you use any management tool (I have used free version of MongoVUE tool)

image

Connecting to server, selecting database, selecting table (sorry, I mean Collection)

MongoClient mc = new MongoClient();
MongoServer ms = mc.GetServer();

MongoDatabase db = ms.GetDatabase(“myforum”);
MongoCollection mcollection = db.GetCollection(“posts”);

Insert/Write record to database

        ADVT advtrecord = new ADVT() {
            advt = “test advertizement”,
            date = DateTime.Now
        };

        mcollection.Insert(advtrecord);

Read records from database

MongoCursor<ADVT> cursor = mcollection.FindAllAs<ADVT>();

dataGridView1.DataSource = cursor.ToList();

 

Safe format to save date/time in SQL Server

Below are safe/general formats which can be used with INSERT/UPDATE statements.

yyyy-mm-dd hh:mm:ss.mmm
yyyy-mm-ddThh:mm:ss.mmm

Delimiters can be / OR – OR space. Examples:

  • 2001-05-21 10:15:50.192
  • 2001-05-21T10:15:50.192
  • 2001-05-21
  • 20010521 10:15:50.192
  • 2001/05/21

SQL example:

UPDATE
    testtable
SET
    testdate = ‘2001-05-21T10:15:50.192’
WHERE
    id = 1   

WARNING: Use this only when you are sure your application IS NOT targeting any other databases (Oracle, MySQL etc.) other than SQL Server.

Please check my previous post as well.

 

ACID and databases

ACID = Atomicity, Consistency, Isolation and Durability

These are a set of properties that guarantee database transactions are reliably processed.

More info available on wiki.

 

ACID and databases

ACID = Atomicity, Consistency, Isolation and Durability

These are a set of properties that guarantee database transactions are reliably processed.

More info available on wiki.