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

System.Exception: SpecifiedUri does not have existing connection. #2341

Open
brandochn opened this issue Mar 9, 2024 · 0 comments
Open

System.Exception: SpecifiedUri does not have existing connection. #2341

brandochn opened this issue Mar 9, 2024 · 0 comments

Comments

@brandochn
Copy link

Hello Guys,

I just play around with sqltoolservice and I did a quick sample using Microsoft StreamJsonRpc as client.

using StreamJsonRpc;
using StreamJsonRpcSample.ConnectionManagementModel;
using StreamJsonRpcSample.Utility;
using System.Diagnostics;


Process? childProcess = Process.Start(new ProcessStartInfo("C:\\Microsoft.SqlTools.ServiceLayer-win-x64-net7.0\\MicrosoftSqlToolsServiceLayer.exe")
{
    RedirectStandardInput = true,
    RedirectStandardOutput = true,
}) ?? throw new Exception("childProcess cannot be null.");

JsonRpc jsonRpc = JsonRpc.Attach(childProcess.StandardInput.BaseStream, childProcess.StandardOutput.BaseStream);

using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
{
    var uri = new Uri(queryTempFile.FilePath);
    var ownerURI = uri.AbsoluteUri;

    ConnectParams connectParams = new ConnectParams
    {
        OwnerUri = ownerURI,
        Connection = new ConnectionDetails
        {
            DataBaseName = myDatabase",
            Password = "myPassword",
            ServerName = "localhost",
            UserName = "sa"
        }
    };

    bool response = await jsonRpc.InvokeWithParameterObjectAsync<bool>("connection/connect", connectParams);

    if (response)
    {
        Console.WriteLine("Connected!!!");
        ListDatabasesParams listDatabasesParams = new ListDatabasesParams
        {
            OwnerUri = ownerURI,
            IncludeDetails = true
        };

        ListDatabasesResponse res = await jsonRpc.InvokeWithParameterObjectAsync<ListDatabasesResponse>("connection/listdatabases", listDatabasesParams);
        foreach (var item in res.DatabaseNames)
        {
            Console.WriteLine(item);
        }
    }
    else
    {
        Console.WriteLine("NO Connected!!!");
    }
}

I got the following error:

StreamJsonRpc.RemoteInvocationException
HResult=0x80131500
Message=System.Exception: SpecifiedUri 'file:///C:/Users/xxx/AppData/Local/Temp/tmp3pbks3.tmp' does not have existing connection
at Microsoft.SqlTools.ServiceLayer.Connection.ConnectionService.ListDatabases(ListDatabasesParams listDatabasesParams) in //src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs:line 1092
at Microsoft.SqlTools.ServiceLayer.Connection.ConnectionService.<>c__DisplayClass95_0.<b__0>d.MoveNext() in /
/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs:line 1342
Source=StreamJsonRpc
StackTrace:
at StreamJsonRpc.JsonRpc.d__151`1.MoveNext()
at Program.<

$>d__0.MoveNext() in C:\Users\xxx\source\repos\StreamJsonRpcSample\StreamJsonRpcSample\Program.cs:line 43

image

image

Versions:
StreamJsonRpc - 2.17.11
sqltoolsservice - 4.12.07
net8.0

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