Skip to content

Instantly share code, notes, and snippets.

@slabarque
Last active February 6, 2019 10:32
Show Gist options
  • Save slabarque/169313c0de54555244cf2ed6732ff98d to your computer and use it in GitHub Desktop.
Save slabarque/169313c0de54555244cf2ed6732ff98d to your computer and use it in GitHub Desktop.
Demonstrates a problem with creating SqlStreamStore schema. ProgramCreatesSchema.cs tries to create the schema. ProgramChecksSchema.cs checks if the schema exists. If ProgramChecksSchema is running, ProgramCreatesSchema is getting timeout exception upon schema creation. If ProgramChecksSchema is not running, then schema is created succesfully
using System;
using System.Threading;
using SqlStreamStore;
namespace TestStreamStoreSchemaExists
{
class Program
{
static void Main(string[] args)
{
bool exists = false;
while (!exists)
{
using (var store = new MsSqlStreamStore(
new MsSqlStreamStoreSettings(@"Server=.\SQLEXPRESS;Database=test;Trusted_Connection=True;")))
{
try
{
var checkSchemaResult = store.CheckSchema().GetAwaiter().GetResult();
if (checkSchemaResult.IsMatch())
{
Console.WriteLine("Store schema found, continuing...");
exists = true;
}
else
{
Console.WriteLine("Store schema not found, waiting...");
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
if(!exists)
Thread.Sleep(5000);
}
Console.WriteLine("done");
Console.ReadKey();
}
}
}
using System;
using System.Threading;
using SqlStreamStore;
namespace TestStreamStoreSchemaCreation
{
class Program
{
static void Main(string[] args)
{
Thread.Sleep(2000);
bool created = false;
while (!created)
{
using (var store = new MsSqlStreamStore(
new MsSqlStreamStoreSettings(@"Server=.\SQLEXPRESS;Database=test;Trusted_Connection=True;")))
{
try
{
var checkSchemaResult = store.CheckSchema().GetAwaiter().GetResult();
if (!checkSchemaResult.IsMatch())
{
Console.WriteLine("Store schema not found, Creating...");
store.CreateSchema().Wait();
}
created = true;
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
if (!created)
Thread.Sleep(5000);
}
Console.WriteLine("done");
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment