Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid column name issues #1149

Open
spj-uk opened this issue Apr 5, 2024 · 1 comment
Open

Invalid column name issues #1149

spj-uk opened this issue Apr 5, 2024 · 1 comment

Comments

@spj-uk
Copy link

spj-uk commented Apr 5, 2024

I have a process where if a database does not exist locally I perform a sync from the server to create the 'template'. It does create it but it looks like the scope info is referring to some old column names. The schema has changed and these are no longer in the database.

I get the following error:.

Invalid column name 'G_Score'.
Invalid column name 'G_Remarks'.

at Dotmim.Sync.RemoteOrchestrator.InternalApplyThenGetChangesAsync(ScopeInfoClient cScopeInfoClient, ScopeInfo cScopeInfo, SyncContext context, ClientSyncChanges clientChanges, DbConnection connection, DbTransaction transaction, CancellationToken cancellationToken, IProgress1 progress) at Dotmim.Sync.Web.Server.WebServerAgent.ApplyThenGetChangesAsync2(HttpContext httpContext, HttpMessageSendChangesRequest httpMessage, SessionCache sessionCache, Int32 clientBatchSize, CancellationToken cancellationToken, IProgress1 progress)
at Dotmim.Sync.Web.Server.WebServerAgent.HandleRequestAsync(HttpContext httpContext, Action1 action, CancellationToken cancellationToken, IProgress1 progress)


INNER EXCEPTION

Invalid column name 'G_Score'.
Invalid column name 'G_Remarks'.

at Microsoft.Data.SqlClient.SqlCommand.<>c.b__203_0(Task1 result) at System.Threading.Tasks.ContinuationResultTaskFromResultTask2.InnerInvoke()
at System.Threading.Tasks.Task.<>c.<.cctor>b__277_0(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
at Dotmim.Sync.BaseOrchestrator.InternalReadSyncTableChangesAsync(ScopeInfo scopeInfo, SyncContext context, Nullable1 excludintScopeId, SyncTable syncTable, BatchInfo batchInfo, Boolean isNew, Nullable1 lastTimestamp, DbConnection connection, DbTransaction transaction, CancellationToken cancellationToken, IProgress1 progress) at Dotmim.Sync.BaseOrchestrator.InternalGetChangesAsync(ScopeInfo scopeInfo, SyncContext context, Boolean isNew, Nullable1 fromLastTimestamp, Nullable1 toNewTimestamp, Nullable1 excludingScopeId, Boolean supportsMultiActiveResultSets, String batchRootDirectory, String batchDirectoryName, DbConnection connection, DbTransaction transaction, CancellationToken cancellationToken, IProgress1 progress) at Dotmim.Sync.RemoteOrchestrator.InternalApplyThenGetChangesAsync(ScopeInfoClient cScopeInfoClient, ScopeInfo cScopeInfo, SyncContext context, ClientSyncChanges clientChanges, DbConnection connection, DbTransaction transaction, CancellationToken cancellationToken, IProgress1 progress)
at Dotmim.Sync.RemoteOrchestrator.InternalApplyThenGetChangesAsync(ScopeInfoClient cScopeInfoClient, ScopeInfo cScopeInfo, SyncContext context, ClientSyncChanges clientChanges, DbConnection connection, DbTransaction transaction, CancellationToken cancellationToken, IProgress1 progress) at Dotmim.Sync.RemoteOrchestrator.InternalApplyThenGetChangesAsync(ScopeInfoClient cScopeInfoClient, ScopeInfo cScopeInfo, SyncContext context, ClientSyncChanges clientChanges, DbConnection connection, DbTransaction transaction, CancellationToken cancellationToken, IProgress1 progress)

Here is my code, it is hitting the exeption when calling the line synchronizeasync with reinitialize.

private async Task SynchroniseTempDB()
{
    try
    {
        Uri uri = new Uri(APIURI + "api/CreateTemp" + $"?oID={OID}&name={$"DBTemp"}");

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);        

        request.Headers.Clear();
        request.Method = "POST";
        request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(Username + ":" + Password));

        string postData = "";
        postData = HttpUtility.UrlEncode("name") + "=" + HttpUtility.UrlEncode(Name) + "&"
            + HttpUtility.UrlEncode("type") + "=" + HttpUtility.UrlEncode(Type) + "&"
            + HttpUtility.UrlEncode("orgID") + "=" + HttpUtility.UrlEncode(OID.ToString());

        byte[] data = Encoding.UTF8.GetBytes(postData);

        request.ContentType = "application/x-www-form-urlencoded";
        request.ContentLength = data.Length;

        Stream requestStream = request.GetRequestStream();
        requestStream.Write(data, 0, data.Length);
        requestStream.Close();

        HttpWebResponse res = (HttpWebResponse)request.GetResponse();

        WebHeaderCollection header = res.Headers;

        var encoding = ASCIIEncoding.UTF8;
        string responseText = "";

        using (var reader = new System.IO.StreamReader(res.GetResponseStream(), encoding))
        {
            responseText = reader.ReadToEnd().TrimStart('"').TrimEnd('"');
        }

        Uri uriSync = new Uri(APIURI + "Inc" + $"?name={IName}");

        var authenticationBytes = Encoding.UTF8.GetBytes($"{Username}:{Password}");
        HttpClient httpClient = new HttpClient();
        httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(authenticationBytes));

        var proxyClientProvider = new Dotmim.Sync.Web.Client.WebRemoteOrchestrator(uriSync.ToString(), client: httpClient);

        string sourcePath = @LocalPath + $"{OrgID}_{IncName}.inc";

        var clientProvider = new SqliteSyncProvider($"Data Source={sourcePath}; Password={DBPassword}");

        proxyClientProvider.HttpClient.Timeout = TimeSpan.FromMinutes(20);

        var progress = new SynchronousProgress<ProgressArgs>(s =>
                   UpdateProgress(s.ProgressPercentage)
               );

        var agent = new SyncAgent(clientProvider, proxyClientProvider, SynchronisationData.Options);

        var serverScope = await proxyClientProvider.GetScopeInfoAsync(); 

        await agent.LocalOrchestrator.DeprovisionAsync();
        await agent.LocalOrchestrator.ProvisionAsync(serverScope);

        var syncResult = await agent.SynchronizeAsync(SyncType.Reinitialize, progress); 

    }
    catch (Exception ex)
    {
        LogError(AppName, AppVersion, GetType().Name, "SynchroniseTempDB", "20", "Error", ex.Message, false);
        SetStatus("Synchronisation failed", Color.Black);
        Close();
    }
}
@spj-uk
Copy link
Author

spj-uk commented Apr 16, 2024

I would have thought deprovisioning and reprovisioning the scope tables would have got round this?

Interestingly if I add the columns to the server side database the sync works and equally these columns do not end up in the local database (which is fine). So it's somewhere on the server scope hanging on but I do not know where?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant