microsoft / microsoft/aspire

User Interface for SqlServer via vscode extension

Open
#10,282 7 comments 2 reactions 0 assignees View on GitHub
area-integrations
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

continuing on https://github.com/dotnet/aspire/issues/6055#issuecomment-3044339466

we can generate a vscode URI that when triggered will open in vscode the sql-server extension and fill out all of the fields and have the user just click "connect"

something like this:

```cs
var sqlServer = builder.AddSqlServer("sql-server")
.WithDataVolume("data");

sqlServer.WithCommand("open-in-vscode", "Open in VS Code", async context =>
{
var rawConnectionString = await sqlServer.Resource.GetConnectionStringAsync();
if (string.IsNullOrEmpty(rawConnectionString))
{
return new ExecuteCommandResult
{
Success = false,
ErrorMessage = "Connection string is not available."
};
}

VsCode.OpenSqlServerInVsCode(rawConnectionString);
return new ExecuteCommandResult { Success = true };
});
```

and the magic:
```cs

using System.Diagnostics;

using Microsoft.Data.SqlClient;

namespace Prevention.SecurityForAI;

public class VsCode
{
public static void OpenSqlServerInVsCode(string rawConnectionString)
{
var connectionString = new SqlConnectionStringBuilder(rawConnectionString);
string server = Uri.EscapeDataString(connectionString.DataSource);
string database = Uri.EscapeDataString(connectionString.InitialCatalog);
string userId = Uri.EscapeDataString(connectionString.UserID);
string password = Uri.EscapeDataString(connectionString.Password);

var vscodeUri = new Uri($"vscode://ms-mssql.mssql/connect?server={server}&database={database}&authenticationType=SqlLogin&user={userId}&password={password}&trustServerCertificate=true");
var process = Process.Start(new ProcessStartInfo
{
FileName = vscodeUri.ToString(),
UseShellExecute = true
});
}
}
```

this requires the https://marketplace.visualstudio.com/items?itemName=ms-mssql.mssql VsCode extension

![Image](https://github.com/user-attachments/assets/fb449d1d-f122-438a-8258-51d8851ce3f2)

@eerhardt / @eerhardt / @davidfowl is this out-of-scope here? should I create a separate issue for this? Maybe having a VsCode extention point that can open UI extensions for specific container based resources

### Describe the solution you'd like

I think adding a URL for the resource would be more naturally but I wasn't sure how to get the connection-string to the `AddUrl` method since it doesn't seem to support async flows.

My current solution is to add a command on the SQL server resource that when invoked will open vscode.

public API (via extension method):
```cs
public static IResourceBuilder WithOpenInVsCodeCommand(this IResourceBuilder builder);
```

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.