From 0ed595b08a866fc1c28dd07a0b21eaa98c0b3ba1 Mon Sep 17 00:00:00 2001 From: Michael Grafnetter Date: Sat, 16 Sep 2023 20:03:18 +0200 Subject: [PATCH] Allow multiple JET instances --- Src/DSInternals.DataStore/DirectoryContext.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Src/DSInternals.DataStore/DirectoryContext.cs b/Src/DSInternals.DataStore/DirectoryContext.cs index eaa55ea..0ef13cf 100644 --- a/Src/DSInternals.DataStore/DirectoryContext.cs +++ b/Src/DSInternals.DataStore/DirectoryContext.cs @@ -7,7 +7,7 @@ public class DirectoryContext : IDisposable { - private const string JetInstanceName = "DSInternals"; + private const string JetInstanceNameFormat = "DSInternals-{0:D}"; private IsamInstance instance; private IsamSession session; @@ -47,8 +47,12 @@ public DirectoryContext(string dbFilePath, bool readOnly, string logDirectoryPat this.DatabaseLogFilesPath = this.DSAWorkingDirectory; } + // Achieve instance name uniquness by appending a GUID to "DSInternals-" + string jetInstanceName = String.Format(JetInstanceNameFormat, Guid.NewGuid()); + // Note: IsamInstance constructor throws AccessDenied Exception when the path does not end with a backslash. - this.instance = new IsamInstance(AddPathSeparator(checkpointDirectoryPath), AddPathSeparator(this.DatabaseLogFilesPath), tempDatabasePath, ADConstants.EseBaseName, JetInstanceName, readOnly, ADConstants.PageSize); + this.instance = new IsamInstance(AddPathSeparator(checkpointDirectoryPath), AddPathSeparator(this.DatabaseLogFilesPath), tempDatabasePath, ADConstants.EseBaseName, jetInstanceName, readOnly, ADConstants.PageSize); + try { var isamParameters = this.instance.IsamSystemParameters;