User Interface for SqlServer via vscode extension
- 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

@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
Assessment
This issue has not been assessed yet.