Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute SQL from within an Azure Data Studio extension?

I want to create an extension for Azure Data Studio that accesses a database. The database (SQL Server) is already available in Azure Data Studio, as I am manually interacting with it.

Reading the Extensible API documentation it seems to be possible to access the databases available in Azure Data Studio. But how do I send SQL queries and receive their replies from within my extension code? What would be the SQL client for my extension code?

like image 868
stefan.at.wpf Avatar asked Dec 01 '25 09:12

stefan.at.wpf


1 Answers

I found no docs about this, however, I found myself this piece of code that works.

I don't know if this is a correct approach.

var connection = await azdata.connection.getCurrentConnection();

if (connection) {
    var uri = await azdata.connection.getUriForConnection(connection.connectionId);
    var g = azdata.dataprotocol.getProvidersByType(
        azdata.DataProviderType.QueryProvider
    )[0] as QueryProvider;
    var t = await g.runQueryAndReturn(
        uri,
        "SELECT TOP 1 * FROM sys.objects"
    );
    var jj = t.rows[0][0];

    vscode.window.showInformationMessage(jj.displayValue);
}
like image 176
Max Avatar answered Dec 05 '25 06:12

Max